如何键入提示类,而不是类的实例?

时间:2015-09-01 02:28:37

标签: typescript typescript1.5

如何键入提示类,而不是类的实例?

我尝试了这个,但我得到了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);

1 个答案:

答案 0 :(得分:5)

使用typeof

class Foo {
}

class Bar extends Foo {
}

class Baz extends Foo {
}

function test(c: typeof Foo) {
    new c();
}

test(Baz);