In my quest to develop an abstract class with an abstract static method, I find myself wanting to override this method in a concrete class. The static nature of the method stems from its responsibility to create a 'copy' from a database model and parse it for frontend usage. To ensure type safety, I aim to limit TypeScript to verifying that the parameters and return type are objects derived from 2 distinct classes, which leads me to consider using generics. Here is a glimpse of what I have in mind:
export abstract class WebModel {
public static getWebModelFromDbModel<A extends WebModel, B extends Model>(dBModel: B): A {
throw some error
}
}
export class concreteWebModel extends WebModel {
public static getWebModelFromDbModel(dbModel: classThatExtendsModel): concreteWebModel {
some implementation
}
}
Yet, WebStorm throws an "incorrectly extends base class" error when dealing with concreteWebModel. Can anyone spot where I might be going wrong?