Currently, I'm enrolled in the Mosh TypeScript course and came across a problem while working on the code. I noticed that the code worked perfectly in Mosh's video tutorial but when I tried it on my own PC and in an online playground, it didn't work as expected. Since I'm not very familiar with this topic, I am unsure of what mistake I may have made in my code.
If anyone has any insights or helpful suggestions, please feel free to comment below and let me know what might be causing the issue in my code.
function Log(target: any, methodName: string, descriptor: PropertyDescriptor) {
const original = descriptor.value as Function;
descriptor.value = function (...args: any) {
console.log("before");
original.call(this, ...args);
console.log("after");
};
}
class Person {
@Log
say(message: string) {
console.log("Person says " + message);
}
}
let person = new Person();
person.say("hello");