The type signature for a non-abstract class (non-abstract constructor function) in TypeScript is the following:
declare type ConstructorFunction = new (...args: any[]) => any;
This is also called a newable type. However, I need a type signature for an abstract class (abstract constructor function). I understand it can be defined as having the type Function
, but that is way too broad. Isn't there a more precise alternative?
Edit:
To clarify what I mean, the following little snippet demonstrates the difference between an abstract constructor and a non-abstract constructor:
declare type ConstructorFunction = new (...args: any[]) => any;
abstract class Utilities {
...
}
var UtilityClass: ConstructorFunction = Utilities; // Error.
Type 'typeof Utilities' is not assignable to type 'new (...args: any[]) => any'.
Cannot assign an abstract constructor type to a non-abstract constructor type.
question from:
https://stackoverflow.com/questions/36886082/abstract-constructor-type-in-typescript 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…