Decorators (TypeScript 5+) in TypeScript
From the TypeScript cheat sheet ยท Decorators ยท verified Jul 2026
Decorators (TypeScript 5+)
Annotate and modify classes and their members with decorator functions
typescript
function log(target: any, context: ClassMethodDecoratorContext) {
return function (...args: any[]) {
console.log(`Calling ${String(context.name)}`);
return target.apply(this, args);
};
}
class Api {
@log
getUsers() { return []; }
}๐ก TypeScript 5+ uses Stage 3 decorators โ different API from the old experimentalDecorators
โก Decorator factories (functions returning decorators) let you pass config parameters
๐ Common in NestJS, Angular, and TypeORM โ less common in React/frontend code
๐ข The context parameter tells you what is being decorated (method, field, class, accessor)
decoratorsclasstypescript-5