The reflect metadata API

We have learned that decorators can be used to modify and extend the behavior of a class's methods or properties. While this is a very good way to get to understand decorator in depth, it is not recommended to use a decorator to modify and extend the behavior of a class. Instead, we should try to use decorators to add metadata to the class being decorated. The metadata can then be consumed by other tools.

The recommendation to avoid using a decorator to modify and extend the behavior of a class could be reverted in the future if the TypeScript team implements a future known as decorator mutation. You can learn more about the status of the decorator mutation proposal at https://github.com/Microsoft/TypeScript/issues/4881 ...

Get Learning TypeScript 2.x - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.