Decorators and Decorator Factories
As we've seen so far, decorators are just special wrapping functions that add behavior to your regular methods, classes, and properties. What's special about them is how they can be used in TypeScript. TypeScript supports the following decorator types:
- Class decorators: These are attached to a class declaration.
- Method decorators: These are attached to a method declaration.
- Accessor decorators: These are attached to a declaration of an accessor of a property.
- Property decorators: These are attached to a property itself.
- Parameter decorators: These are attached to a single parameter in a method declaration.
And consequently, there are five different places where you can use decorators, so that means that there are five different kinds of special functions that can be used to decorate your code. All of them are shown in the following example:
@ClassDecorator class SampleClass { ...