blow-metadata

0.1.0 • Public • Published

blow-metadata

Set of helpers for ES7 Reflection API / Decorators

function ReturnType() {
  return function(target, property) {
     const type = Metadata.get(target).returnType(target, property);
     const oldMethod = target[property];
     target[property] = function() {
       const Type = type.mapper;
       return new Type(oldMethod.apply(null, arguments)); 
     }
  }
}
 
class Demo {
 
  @ReturnType()
  stringMethod(input): string {
    return input;
  }
  
  @ReturnType()
  numberMethod(input): number {
    return input;
  }
  
}
 
const demo = new Demo();
 
console.log(demo.stringMethod('10')); // '10'
console.log(demo.stringMethod(10)); // '10'
 
console.log(demo.numberMethod('10')); // 10
console.log(demo.numberMethod(10)); // 10

Package Sidebar

Install

npm i blow-metadata

Weekly Downloads

1

Version

0.1.0

License

MIT

Last publish

Collaborators

  • mchmielarski