Typescript TS1238:作为表达式调用时无法解析类装饰器的签名
我看到以下编译错误: TS1238:调用为时无法解析类装饰器的签名 表情 代码如下:Typescript TS1238:作为表达式调用时无法解析类装饰器的签名,typescript,tsc,typescript3.0,Typescript,Tsc,Typescript3.0,我看到以下编译错误: TS1238:调用为时无法解析类装饰器的签名 表情 代码如下: const fdec = function(target:any, field: any, desc: any){ console.log('target 0 :', target); target.bar = 3; return target; }; const fdec2 = function(){ console.log('target 1:'); return function(t
const fdec = function(target:any, field: any, desc: any){
console.log('target 0 :', target);
target.bar = 3;
return target;
};
const fdec2 = function(){
console.log('target 1:');
return function(target:any, field: any, desc: any){
console.log('target 2:', target);
target.bar = 3;
return target;
}
};
@fdec
@fdec2()
class Foo {
static bar: number
}
console.log(Foo.bar);
console.log(new Foo());
有人知道如何修复该错误吗?类装饰器的签名(如lib.d.ts中所示)必须如下所示:
declare type ClassDecorator = <TFunction extends Function>(target: TFunction) => TFunction | void;
const fdec = function (target: any) {
console.log('target 0 :', target);
target.bar = 3;
return target;
};
const fdec2 = function () {
console.log('target 1:');
return function (target: any) {
console.log('target 2:', target);
target.bar = 3;
return target;
}
};
@fdec
@fdec2()
class Foo {
static bar: number
}
console.log(Foo.bar);
console.log(new Foo());