blow-metadata
v0.1.0
Published
Set of helpers for ES7 Reflection API / Decorators
Downloads
2
Maintainers
Readme
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