类方法参数的装饰器

本篇文章将介绍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) {
  }
}

版权声明:本文为weixin_43800535原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。