0 votes
in TypeScript - JavaScript's Superset by
Explain Decorators in Typescript?

1 Answer

0 votes
by

A Decorator is a special kind of declaration that can be applied to classes, methods, accessor, property, or parameter. Decorators are simply functions that are prefixed @expression symbol, where expression must evaluate to a function that will be called at runtime with information about the decorated declaration.

TypeScript Decorators serves the purpose of adding both annotations and metadata to the existing code in a declarative way. Decorators are an experimental feature proposed for ES7. It is already in use by some of the JavaScript frameworks including Angular 2. The Decorators may change in future releases.

To enable experimental support for decorators, we must enable the experimentalDecorators compiler option either on the command line or in our tsconfig.json:

Command Line

$tsc --target ES5 --experimentalDecorators    

tsconfig.json

{    

    "compilerOptions": {    

        "target": "ES5",    

        "experimentalDecorators": true    

    }    

}  

Related questions

0 votes
asked Mar 23, 2022 in TypeScript - JavaScript's Superset by sharadyadav1986
0 votes
asked Mar 23, 2022 in TypeScript - JavaScript's Superset by sharadyadav1986
...