Levart9999 / stomat

0 stars 0 forks source link

universal cinstructor for models #3

Open yarscript opened 1 month ago

yarscript commented 1 month ago

https://www.typescriptlang.org/docs/handbook/utility-types.html

export abstract class BaseEntity<T> {
  constructor(options: Partial<T>) {
    Object.keys(options).forEach((k) => (this[k] = options[k]));
  }
}

export class Favour extends BaseEntity<Favour> {
  id: string;

  title: string;

  price: string;

  // constructor(options: Partial<Order>) {
  //   Object.keys(options).forEach((k) => (this[k] = options[k]));
  // }
  // constructor(title: string, price: string) {
  //   this.title = title;
  //   this.price = price;
  // }
}

new Favour({ price: '23' });

type generics

Levart9999 commented 1 month ago

@yarscript