[英]How can I type hint a class, rather than an instance of the class?
How can I type hint a class, rather than an instance of the class? 如何键入提示类,而不是类的实例?
I tried this, but I get Cannot use 'new' with an expression whose type lacks a call or construct signature.
我试过这个,但是我得到了
Cannot use 'new' with an expression whose type lacks a call or construct signature.
class Foo {
}
class Bar extends Foo {
}
class Baz extends Foo {
}
function test(c: Foo) {
new c();
}
test(Baz);
Use typeof
: 使用
typeof
:
class Foo {
}
class Bar extends Foo {
}
class Baz extends Foo {
}
function test(c: typeof Foo) {
new c();
}
test(Baz);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.