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

Not possible to overload Model methods #124

Open
maasencioh opened this issue Nov 29, 2021 · 0 comments
Open

Not possible to overload Model methods #124

maasencioh opened this issue Nov 29, 2021 · 0 comments

Comments

@maasencioh
Copy link

Currently, if I have a model that needs to be validated on the creation I'll try to overload the creation function. The problem is that this leads to the following error

export default class User extends BaseModel {
  @field()
  public _id: ObjectId;
  public firstName: string;
  public lastName: string;
  public fullName?: string;

  public static create(data: Partial<ModelAttributes<User>>) {
    const newData = { ...data, fullName: firstName + lastName };
    return super.create(newData);
  }
}
Class static side 'typeof User' incorrectly extends base class static side '{ readonly $fieldsDefinitions: Map<string, FieldOptions>; $addField(name: string, options?: Partial<FieldOptions> | undefined): FieldOptions; ... 16 more ...; getCollection<ModelType extends MongodbModel<...>>(this: ModelType, connection?: string | undefined): Promise<...>; }'.
  The types returned by 'create(...)' are incompatible between these types.
    Type 'Promise<MongodbDocument<unknown>>' is not assignable to type 'Promise<InstanceType<ModelType>>'.
      Type 'MongodbDocument<unknown>' is not assignable to type 'InstanceType<ModelType>'.
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