Summary

In this chapter, we learned how to consume and implement the four available types of decorators (class, method, property, and parameter). We used decorators to mutate the original classes to understand how they work but we also learned that we should avoid using decorators to mutate the prototype of a class. We also learned how to create a decorator factory to abstract developers from the decorator types when they are consumed, how to pass configuration to a decorator, and how to use the reflection metadata API to access type information at runtime. As we have already mentioned, decorators in TypeScript are still an experimental feature, which doesn't mean that they are not ready for their usage in production systems but that their ...

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.