Abstract constructor type in TypeScript

前端 未结 4 1370
眼角桃花
眼角桃花 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:41

    Having the same problem. I guess, an essence of abstract class constructor signature is an absense of new ( ... ) : X thingy in its declaration. That's why it can be declared explicitly.

    However. You can do this, and it will compile.

    var UtilityClass: typeof Utilities  = Utilities;
    

    typeof Something is a nice way to reference constructor types, however, it cannot be extended.

    And in any case you can do thing like this:

    var UtilityClass: ConstructorFunction =  Utilities;
    

提交回复
热议问题