reflect-metadata provides a polyfill for the Metadata Reflection API, a non-standardized API that gained traction through TypeScript's `--experimentalDecorators` feature. The package is currently at version 0.2.2 and sees infrequent but consistent maintenance, with the most recent patch release (0.2.2) addressing minor fixes. While the original TC39 proposal for Decorator Metadata is no longer being considered for standardization, this package continues to be essential for projects that rely on TypeScript's legacy decorator implementation, such as many Angular or older NestJS applications. Its primary differentiator is providing the `Reflect` global object and its methods (`Reflect.defineMetadata`, `Reflect.getMetadata`, etc.) to enable runtime reflection of metadata attached via decorators, which is not natively supported by standard JavaScript or modern decorator proposals. It offers both a full bundle with internal polyfills for `Map`, `Set`, and `WeakMap` for older runtimes, and a lighter `/lite` version without these internal polyfills.
npm install reflect-metadataVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to define and retrieve custom metadata using `Reflect.defineMetadata` and `Reflect.getMetadata` with class, method, and property decorators, along with an example of TypeScript's `design:paramtypes` metadata.
Projects relying on this API should be aware of its non-standard status and consider migration to standard decorators if possible. This package will continue to support legacy usage.
Always import `reflect-metadata` for its side effects to patch the global `Reflect` object: `import "reflect-metadata";` or `require("reflect-metadata");`. Ensure this import occurs before any code that uses decorators or `Reflect` methods.Upgrade immediately to `0.1.12` or later.
Use `import "reflect-metadata/lite";` only if you are targeting environments with native `Map`, `Set`, and `WeakMap` support, or if you are providing these polyfills through another means (e.g., `core-js`). Otherwise, use the standard `import "reflect-metadata";`.
Add both `"experimentalDecorators": true` and `"emitDecoratorMetadata": true` to the `"compilerOptions"` section of your `tsconfig.json`.
Ensure `import "reflect-metadata";` (or `require("reflect-metadata");`) is at the very top of your application's entry point, or linked as a `<script>` tag for browser environments, *before* any code that uses decorators or `Reflect` methods.Verify that `import "reflect-metadata";` is the *first* statement in your main application file. If using bundlers, ensure it's not tree-shaken away or executed out of order.
In `tsconfig.json`, ensure `"experimentalDecorators": true` is set under `"compilerOptions"`.
In `tsconfig.json`, ensure `"emitDecoratorMetadata": true` is set under `"compilerOptions"`.
No dependency data recorded yet.