Is there a type for “Class” in Typescript? And does “any” include it?

后端 未结 7 803
渐次进展
渐次进展 2020-12-07 18:34

In Java, you can give a class to a method as a parameter using the type \"Class\". I didn\'t find anything similar in the typescript docs - is it possible to hand a class to

7条回答
  •  抹茶落季
    2020-12-07 19:15

    The simplest solution would be let variable: typeof Class.

    Here an example:

    class A {
      public static attribute = "ABC";
    }
    
    function f(Param: typeof A) {
      Param.attribute;
      new Param();
    }
    
    
    f(A);
    

提交回复
热议问题