In TypeScript I use Java like type Class:
interface Class<T = void> {
new(...args: any[]): T;
}
However, such type doesn't work with abstract classes:
abstract class Bar {}
class Foo {
test(clazz: Class) { }
doIt() {
this.test(Bar);//ERROR
}
}
The error I get is Argument of type 'typeof Bar' is not assignable to parameter of type 'Class<void>'. When class Bar is not abstract then everything is ok.
I understand, that the problem is that declaring Class we say it is possible to use new operator, but we can't use this operator for abstract classes. However, I need a type, that could be suitable both for non abstract and abstract classes (abstract classes are classes too). If it is possible, could anyone say how to do it?
this.test(Bar);when you do this you don't pass an instance but the actual definition of the class. But the argument you specified on the functiontest(clazz: Class) { }does expect and instance of Class.new Bar()would solve this, but that obv won't work with abstract classes. The whole point of abstract classes is that they can't be instances, they have to be implemented. So I'm kinda confused on why you are intending to use this abstract class for this.