O'Reilly logo

Learning Angular for .NET Developers by Rajesh Gunasundaram

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Class decorators

Class decorators are declared before the class declaration. Class decorators can observe, modify, and replace the definition of a class by applying to the constructor of that class. The signature of ClassDecorator in TypeScript is as illustrated:

declare type ClassDecorator = <TFunction extends Function>(target: TFunction) => TFunction | void; 

Consider a Customer class, and we would like that class to be freezed. Its existing properties should not be removed and 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required