Friday, September 21, 2018

Typescript Beginner Guide to Decorators basics with examples

Typescript Decorators examples

Typescript Decorators

Typescript introduced decorators, Decorators is a one of a design pattern in an object-oriented program.

Decorator Design pattern

Design patterns are solutions to repeated problemsn. This pattern allows adding functions and behavior to objects dynamically. This will not affect the overall behavior of objects of a class.

Typescript decorators can be applied to 
  • Methods
  • Classes
  • Properties
  • parameters
  • Accessor
These are experimental features, This might change in future versions. This will not be available to code normally.

We have to doCompilerpoiler configurations - experimentalDecorators to enable it.

This can be done via command line or tsconfig.json.

tsc --target ES5 --experimentalDecorators
{
    "compilerOptions": {
        "target": "ES5",
        "experimentalDecorators": true
    }
}
We will see the decorator examples in future posts
Class Decorator and Examples

Related article


EmoticonEmoticon