Abstract constructor type in TypeScript

前端 未结 4 1374
眼角桃花
眼角桃花 2020-12-14 15:03

The type signature for a non-abstract class (non-abstract constructor function) in TypeScript is the following:

declare type ConstructorFunction = new (...ar         


        
4条回答
  •  一整个雨季
    2020-12-14 15:55

    The whole point with abstract classes (in OO in general) is that you can not instantiate them, you need a concrete non-abstract implementation.

    I assume that you want to have different implementations to that abstract class and want to be able to receive one of those implementations (as a parameter or something of the likes).
    If that's the case, then maybe this might solve your problem:

    declare type ConstructorFunction = new (...args: any[]) => T;
    
    abstract class Utilities { }
    
    class MyUtilities extends Utilities { }
    
    var UtilityClass: ConstructorFunction = MyUtilities; 
    

提交回复
热议问题