angular + restangular + 打字稿装饰器错误

angular + restangular + typescript decorators error

我正在使用:

这是我的代码:

  function plain(){
    return (target: Object, propertyKey: string, descriptor: TypedPropertyDescriptor<any>) => {
      var originalMethod = descriptor.value; // save a reference to the original method
      descriptor.value = function(...args: any[]) {
        var result = originalMethod.apply(this, args);
        return result.then(function stripRestangularAttributes(response){
          return response.plain();
        });
      };
      return descriptor;
    };
  }

  export class XYZ {
    @plain
    public getSomethingBySomething(data: Data): restangular.IPromise<any> {
      if (!entityKey && !period) {
        return null;
      }
      return this.restangularElement.all("route1/route2").post(data);
    }
  }

我收到以下错误:

error TS1241: Unable to resolve signature of method decorator when called as an expression. Supplied parameters do not match any signature of call target.

@plain行抛出。

一些信息:

我想:

不幸的是,我无法理解上面示例中 typescript 抱怨的内容。

PS 我一直在阅读 作为我的 TS 装饰器指南。

根据规范,您的方法装饰器不应 return 函数:

declare type MethodDecorator = <T>(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T> | void;

试试这个:

function plain(target: Object, propertyKey: string, descriptor: TypedPropertyDescriptor<any>) {
    var originalMethod = descriptor.value; // save a reference to the original method
    descriptor.value = function(...args: any[]) {
        var result = originalMethod.apply(this, args);
        return result.then(function stripRestangularAttributes(response){
            return response.plain();
        });
    };
    return descriptor;
};