reflect-metadata and Design Types
Capture parameter and property types at runtime.
reflect-metadata and Design Types
Before standardized metadata existed, TypeScript could emit design-time type information at runtime via the reflect-metadata library plus the emitDecoratorMetadata compiler flag. This lesson covers that older but still widely used mechanism.
Enabling the Feature
Two things are required: turn on the compiler options and import the library once at the program entry point.
// tsconfig.json
// {
// "compilerOptions": {
// "experimentalDecorators": true,
// "emitDecoratorMetadata": true
// }
// }
import "reflect-metadata";All lessons in this course
- Stage 3 Decorators Explained
- Decorator Metadata
- reflect-metadata and Design Types
- Building a Decorator Framework