typescript中的MethodDecorator如何传入类型?

// 这是ts内部定义的方法装饰器类型
declare type MethodDecorator = <T>(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T> | void;
const Logger: MethodDecorator = function(target, property, descriptor) {
  descriptor.value = function() {} // 报错,我如何将Function传入MethodDecorator
  console.log('logger...')
}

class User {
  @Logger
  create() {
    console.log('create...')
  }
}
阅读 2.6k
1 个回答
- const Logger: MethodDecorator = function(target, property, descriptor) {
+ const Logger: MethodDecorator = function(target, property, descriptor: PropertyDescriptor) {
logo
Microsoft
子站问答
访问
宣传栏