I'm trying to create a base crud service that takes a Sequelize model and creates all basic APIs for it so what I have done it this:
export class RepositoryService<T extends Model<T>> {
constructor(protected model: typeof Model) {
}
public async getMany(
query: RequestParamsParsed = {},
options: RestfulOptions = {},
): Promise<T[]> {
return this.model.findAll();
}
}
I'm getting the following error:
The 'this' context of type 'typeof Model' is not assignable to method's 'this' of type 'new () => Model<Model<any>>'.
Cannot assign an abstract constructor type to a non-abstract constructor type.
this is because of this line in the seqeulize-typescript package:
static findAll<T extends Model<T>>(this: (new () => T), options?: IFindOptions<T>): Promise<T[]>;
I'm relatively new to Typescript so if anyone can tell me what's the meaning of this: (new () => T) in the findAll function and how can I work this out.
arg: (new () => T)means that arg is not instance of typeTlike in(arg: T). arg is class T. Also you can use this syntax for that(arg: { new (...args): T })