Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model Generation V2.0 #1

Open
EdmilsonRodrigues opened this issue Oct 28, 2024 · 0 comments
Open

Model Generation V2.0 #1

EdmilsonRodrigues opened this issue Oct 28, 2024 · 0 comments

Comments

@EdmilsonRodrigues
Copy link
Owner

export class Model {
  private _id: number;
  private _name: string;
  imageUrl: string;

  constructor(id: number, name: string, imageUrl: string) {
    this.id = id;
    this.name = name;
    this.imageUrl = imageUrl;
  }

  get id(): number {
    return this._id;
  }

  set id(value: number) {
    if (value <= 0) throw new Error("ID must be greater than 0");
    this._id = value;
  }

  get name(): string {
    return this._name;
  }

  set name(value: string) {
    if (value.length < 8) throw new Error("Name must be at least 8 characters long");
    this._name = value;
  }
}

This is how to ensure contrains in a typescript model.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant