类方法参数的装饰器

本篇文章将介绍TypeScript中类方法参数的装饰器。

定义类方法参数装饰器

// target: 类原型
// method: 类方法名
// paramIndex: 装饰器修饰参数的索引
function parameterDecorator(target: any, method: string, paramIndex: number) {
  console.log(target,method,paramIndex)
}

class Test6{
  getInfo(name:string,@parameterDecorator age:number) {
  }
  getInfo2(@parameterDecorator name:string,age:number) {
  }
}

猜你喜欢

转载自blog.csdn.net/weixin_43800535/article/details/124507779
今日推荐