I'm using TS 5.0.4 & Node 20.2
When running my program Node throws an invalid or unexpected token error when applying my decorator to my class method.
My basic decorator:
export function Auth(role: string) {
return function (originalMethod: any, context: ClassMethodDecoratorContext) {
const methodName = String(context.name);
function replacementMethod(this: any, ...args: any[]) {
console.log("Role", role);
console.log(`LOG: Entering method '${methodName}'.`);
console.log(args);
const result = originalMethod.call(this, ...args);
console.log(`LOG: Exiting method '${methodName}'.`);
return result;
}
return replacementMethod;
};
}
export class TestClass {
@Auth("ADMIN")
testMethod() {
console.log("test");
}
}
I assumed node had support for Decorators or typescript would polyfill it?