I have encountered an interesting problem. I have an abstract class with a static method that I want multiple other classes to extend.
I want to provide all of these uninstantiated classes as an array to a method in another class. This other classes method would instantiate them if the value returned from the class static method is false.
Here is some example code to illustrate my issue:
abstract class Abstract {
public static defer() {
return true;
}
}
class MyClass extends Abstract {}
class OtherClass {
public add(my_classes: Array<new () => Abstract>) {
const x = my_classes[0].defer();
const y = new my_classes[0]();
}
}
const other_class = new OtherClass();
other_class.add([MyClass]);
On the line const x = my_classes[0].defer(); I get the following error:
Property 'defer' does not exist on type 'new () => Abstract'.ts(2339)
If I switch the my_classes param to have the type of Array<typeof Abstract> I get the following error when trying to instantiate it:
Cannot create an instance of an abstract class.(2511)
How do I call a static method in this circumstance and also be able to create a new instance of the class?