Looking to add a new property to a class using a class decorator?
Here's an example:
@MyClassDecorator
class MyClass {
myFirstName: string;
myLastName: string;
}
// Need to achieve something like this:
function MyClassDecorator (target: any): any {
target['myNickname'] = 'Gambler';
}
let myClass = new MyClass();
console.log(myClass['myNickname']); // Expecting "Gambler" but receiving "undefined"
How can we troubleshoot this issue?
Can a property be added to a class using a decorator?
Appreciate your insights!