TypeScript中非抽象类(非抽象构造函数)的类型签名如下:
declare type ConstructorFunction = new (...args: any[]) => any;
这也被称为newable型.但是,我需要abstract类(抽象构造函数)的类型签名.我知道它可以定义为Function
型,但way型太宽了.难道没有更精确的替代方案吗?
Edit:
为了阐明我的意思,下面的小片段演示了抽象构造函数和非抽象构造函数之间的区别:
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'.
无法将抽象构造函数类型分配给非抽象构造函数类型.