Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typescript TS1238:作为表达式调用时无法解析类装饰器的签名_Typescript_Tsc_Typescript3.0 - Fatal编程技术网

Typescript 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

我看到以下编译错误:

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(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());