I am currently working on developing a foundational Model that will serve as the base for a specific model class, which will have an interface detailing its attributes.
Within the base Model class, I am aiming to incorporate a static factory() function that will create an instance of the model from the static context and return a type comprising the specific model, base model, and specified interface.
An issue arises when using the static function U extends Model<T>
, where T triggers an error message stating: "Static members cannot reference class type parameters."
Interface Event
interface Event {
id: number;
}
Base Event Model
export class Model<T> {
public static factory<U extends Model<T>>(this: { new(): U }, data: any): U {
return Object.assign(new this(), data);
}
}
Event Model
export class EventModel extends Model<Event> {}
The ultimate objective is to achieve a return type of EventModel that encompasses all the properties defined within Event.