What is “Decorators” in TypeScript?

Technology CommunityCategory: TypeScriptWhat is “Decorators” in TypeScript?
VietMX Staff asked 3 years ago

Decorator is a special kind of declaration that can be attached to a class declaration, method, accessor, property, or parameter. Decorators are functions that take their target as the argument. With decorators we can run arbitrary code around the target execution or even entirely replace the target with a new definition.

There are 4 things we can decorate in ECMAScript2016 (and Typescript): constructors, methods, properties and parameters.