When working with TypeScript, I often utilize a Java-like type called Class
:
interface Class<T = void> {
new(...args: any[]): T;
}
Unfortunately, this type doesn't seem to be compatible with abstract classes:
abstract class Bar {}
class Foo {
test(clazz: Class) { }
doIt() {
this.test(Bar);//ERROR
}
}
Upon attempting this, I receive an error stating that "Argument of type 'typeof Bar' is not assignable to parameter of type 'Class<void>'". This issue arises because the new
operator cannot be used with abstract classes. Hence, I'm seeking a type that can cater to both abstract and non-abstract classes. Is there a way to achieve this?