Decorators — TypeScript · Foundations

@Controller('cats') and @Get(':id') are ordinary functions that run when a class is defined. Write your own: a class decorator and method decorators that record routes, and one that wraps a method to log its calls.

What you will learn

Read the theory for Decorators

All TypeScript lessons

All Foundations courses

loading types…

What you'll learn

  • Write class and method decorators, and decorator factories that take arguments
  • Explain when decorators run and in what order, and what each kind receives
  • Wrap a method through its property descriptor without losing this or its return value