Recently, I encountered a situation where I needed to utilize an abstract class.
export abstract class ABaseModel {
public static isKeyOf<T>(propName: (keyof T)): string {
return propName;
}
}
Following that, I also created another class which extends the abstract class:
export class Model extends ABaseModel {
public id: number;
public uid: string;
public createdByUid: string;
}
In order to verify if a given string is a valid property of the Model class, one would typically do this:
Model.isKeyOf<Model>('id');
However, my goal was to simplify this and be able to write:
Model.isKeyOf('id');
I wondered if Type Inference could make this possible without the need for explicit type definitions.