How can I add a new property to a class using a class decorator?
Code for example:
@MyClassDecorator
class MyClass {
myFirstName: string;
myLastName: string;
}
// I need something like this:
function MyClassDecorator (target: any): any {
target['myNickname'] = 'Gambler';
}
let myClass = new MyClass();
console.log(myClass['myNickname']); // expecting "Gambler" but got "undefined"
How to fix this code?
Is it possible at all to add a property to a class using decorator?
Thanks!
See Question&Answers more detail:os