I recently started using TypeScript and encountered an implementation issue. I'm working on a class that takes another class as an argument. The challenge is that it can be any class, but I want to define certain possible class properties or methods. Let's assume this class may have a singleton
static property. I attempted to utilize a Class generic:
type Class<T> = new (...args: any[]) => T;
class ClassResource {
private _resource;
private _singleton;
constructor(resource: Class<any>) {
this._resource = resource;
this._singleton = resource.singleton;
}
// some methods
getClassInstance() {
return new this._resource();
}
}
However, I encountered the following error:
Property 'singleton' does not exist on type 'Class'
How can I properly define this "abstract" class and specify only specific potential properties without restricting them?