TypeScript Reflect.getMetadata & Reflect.defineMetadata All In One
TypeScript Reflect.getMetadata & Reflect.defineMetadata All In One
$ npm i reflect-metadata
# $ npm i -S reflect-metadata
# $ npm i --save reflect-metadata

https://www.npmjs.com/package/reflect-metadata
https://github.com/rbuckton/reflect-metadata
export function controller(target: any) {
  for (const key in target.prototype) {
    // Object.prototype.hasOwnProperty()
    console.log('key', key);
    Reflect.getMetadata('path', target.prototype, key);
    // Property 'getMetadata' does not exist on type 'typeof Reflect'.ts(2339)
  }
}
export function get(path: string) {
  return function (target: any, key: string) {
    Reflect.defineMetadata('path', path, target.prototype, key);
    // Reflect.defineProperty(target, propertyKey, attributes);
  }
}
export function post(target: any) {
  //
}
export function put(target: any) {
  //
}
// Identifier expected. 'delete' is a reserved word that cannot be used here.ts(1359)
// export function delete(target: any) {
//   //
// }
export function Delete(target: any) {
  //
}
Reflect
The static Reflect.defineProperty() method is like Object.defineProperty() but returns a Boolean.
静态 Reflect.defineProperty() 方法类似于 Object.defineProperty() 但返回一个布尔值。
Reflect.defineProperty(target, propertyKey, attributes);
refs
©xgqfrms 2012-2020
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/16152988.html
未经授权禁止转载,违者必究!

 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号