Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.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 从方法装饰器获取方法的签名_Typescript_Typescript2.0_Typescript Decorator - Fatal编程技术网

Typescript 从方法装饰器获取方法的签名

Typescript 从方法装饰器获取方法的签名,typescript,typescript2.0,typescript-decorator,Typescript,Typescript2.0,Typescript Decorator,我有这样一个方法装饰器: export function NumberMethodDecorator(message: string) { return (target: object, propertyKey: string, descriptor?: TypedPropertyDescriptor<any>) => { // do some stuff here } } 但是,我想确保numbermethodecorator仅应用于签名为(value:nu

我有这样一个方法装饰器:

export function NumberMethodDecorator(message: string) {
  return (target: object, propertyKey: string, descriptor?: TypedPropertyDescriptor<any>) => {
    // do some stuff here
  }
}
但是,我想确保
numbermethodecorator
仅应用于签名为
(value:number)=>any
的方法


如何执行此操作?

TypedPropertyDescriptor
的类型参数中指定:

export function NumberMethodDecorator(message: string) {
  return (
    target: object, propertyKey: string,
    descriptor?: TypedPropertyDescriptor<(value: number) => any>
  ) => {
    // do some stuff here
  };
}
export function NumberMethodDecorator(message: string) {
  return (
    target: object, propertyKey: string,
    descriptor?: TypedPropertyDescriptor<(value: number) => any>
  ) => {
    // do some stuff here
  };
}
class SomeClass {
  @NumberMethodDecorator("") // ok
  someMethod(value: number) {

  }

  @NumberMethodDecorator("") // compile error
  otherMethod() {
  }
}