new(...args: any[]) => T
和{ new(...args: any[]): T }
有什么区别,我应该使用哪一个?
答案 0 :(得分:0)
它们是别名,并且它们都不支持静态字段:
class X {
static staticAttr = 42;
static method() { }
attr: string;
}
interface A {
Attr1: { new (...args): X }
Attr2: new(...args: any[]) => X
}
let fn = (arg: A) => {
arg.Attr1.staticAttr // Property 'staticAttr' does not exist on type 'new (...args: any[]) => X'
(new arg.Attr1()).attr;
(new arg.Attr2()).attr;
}
TS将 { new(...args: any[]): T
映射到new(...args: any[]) => T
中。所以我认为new(...args: any[]) => T
会更好,但没什么大不同