【发布时间】:2019-08-01 08:21:59
【问题描述】:
请帮我解决打字稿错误,我花了一天时间还没有解决。
编译后功能正常,只是TS错误。
它是表达式类型的类装饰器。我正在尝试克隆原始构造函数并在初始化之前对其进行包装和处理。
我有 2 个错误。
最后一次返回
'(...args: any[]) => T' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Function'.
一个新的运算符
'(...args: any[]) => T' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Function'.
代码:
export const test : ClassDecorator = < T extends Function >( ctor : T ) : T => {
let orig = ctor ;
const test = function( ...args : any[] ) : T {
// Processing
return new orig() ;
} ;
return test ;
} ;
@test
Class Foo {}
非常感谢您的建议。
我尝试了很多方法来解决它,比如{ new () : T } 等等,但都没有奏效。
【问题讨论】:
-
我猜,返回的对象应该是
T类型的 -
你能举个例子吗?我猜它可能会引发另一个错误
-
分享
new orig()的代码 -
orig() 没有代码。如果你把这些代码放在编辑器上就可以了。
-
return new orig();的位置,您可能有导入或为此编写的任何函数/类
标签: javascript typescript