Decorators Overview
Decorators attach behaviour to classes and methods. TypeScript 5 supports standard decorators.
Example
function logged(fn: Function, ctx: ClassMethodDecoratorContext) {
return function (this: any, ...a: any[]) { console.log("call", String(ctx.name)); return fn.apply(this, a); };
}
class S { @logged hi() { return "hi"; } }
console.log(new S().hi());Result
call hi hi
Exercise
Apply decorator.
loggedQuiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.