From the course: TypeScript Essential Training

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

What are decorators and why are they helpful?

What are decorators and why are they helpful? - TypeScript Tutorial

From the course: TypeScript Essential Training

What are decorators and why are they helpful?

- [Instructor] In this chapter, I'm going to show how to use an incredibly powerful type-script feature named decorators. The easiest way to understand decorators is to think of them as metadata that you can add to your classes, methods and even, getter and setter properties. In fact, you can add far more than just information. You can actually extend these elements with additional behavior, allowing you to add that behavior to your code without actually changing your code. The typical example of decorators in action is a logging decorator. Let me show you. This example class has logging statements at the beginning and end of each function. This helps diagnose problems more quickly because you can determine which functions have run and whether or not they completed. It also features a mechanism that protects the method from being called by users who don't have proper access. Though this is the behavior that we want,…

Contents