Decorator overview
In this section of the chapter, we will take a look at the general setup and syntax of decorators, what we need to do to enable them, and how they are applied to classes. We will also show how multiple decorators can be used at the same time, and then discuss the different types of decorators. Finally, this section will take a look at decorator factories, and how we can pass parameters into decorator functions.
Decorator setup
Decorators are an experimental feature of the TypeScript compiler and are supported in ES5 and above. In order to use decorators, we need to enable a compile option in the tsconfig.json
file. This option is named experimentalDecorators
, and needs to be set to true
, as follows:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"strict": true,
"experimentalDecorators": true,
"skipLibCheck": true...