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
Back to the full TypeScript cheat sheet