【发布时间】:2020-08-20 03:25:12
【问题描述】:
尝试使用静态属性扩展类,但出现以下类型错误:
Property 'property' does not exist on type 'new (...args: any[]) => T'.(2339)
class A {
static property = 'a'
}
class B extends A {}
function factory<T extends A>(type: new (...args: any[]) => T): T {
if (type.property) { // error -> Property 'property' does not exist on type 'new (...args: any[]) => T'.(2339)
console.log('heyyyyy')
}
return new type();
}
const b = factory(B);
console.log(B.property)
必须做些什么才能在没有类型错误的情况下工作?
感谢您的帮助。
【问题讨论】:
标签: typescript generics