July 2017
Intermediate to advanced
454 pages
10h 1m
English
Class decorators are declared above the class declaration. Class decorators can observe, modify, and replace a class' definition that it is decorated by applying to the constructor of that class. The signature of ClassDecorator in TypeScript is as follows:
declare type ClassDecorator = <TFunction extends Function>(target:
TFunction) => TFunction | void;
Consider a Customer class; we would like that class to be frozen. Its existing properties should not be removed or new properties should not be added.
We can create a separate class that can take any object and freeze it. We can then decorate the customer class with @freezed to prevent adding new properties or removing the existing properties from the class:
@freezed class ...
Read now
Unlock full access