如何键入提示类,而不是类的实例?
我尝试了这个,但我得到了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);
答案 0 :(得分:5)
使用typeof
:
class Foo {
}
class Bar extends Foo {
}
class Baz extends Foo {
}
function test(c: typeof Foo) {
new c();
}
test(Baz);