Typescript装饰器定义方法签名

时间:2020-03-09 20:01:15

标签: javascript typescript decorator

是否可以使用ts装饰器来推断方法的签名?像这样:


interface Events {
  ready: (msg: string) => any;

  close: (msg: string) => any;

  count: (num: number) => any;
}

function BindEvent<K extends keyof Events>(event: K) {
  return function(target, method, descriptor) {
    // do something
  } as Events[K];
}

class MyClass {
  @BindEvent<'ready'>('ready')
  public myMethod() // => (msg: string) => any
}

0 个答案:

没有答案