|
1 | 1 | # Metadata Reflection API
|
2 | 2 |
|
| 3 | +NOTE: Now that both [Decorators](https://github.com/tc39/proposal-decorators) and |
| 4 | +[Decorator Metadata](https://github.com/tc39/proposal-decorator-metadata) have achieved Stage 3 within TC39, the API |
| 5 | +proposed below is no longer being considered for standardization. However, this package will continue to support |
| 6 | +projects that leverage TypeScript's legacy `--experimentalDecorators` option as some projects may not be able to migrate |
| 7 | +to use standard decorators. |
| 8 | + |
3 | 9 | * [Detailed proposal][Metadata-Spec]
|
4 | 10 |
|
5 | 11 | ## Installation
|
|
8 | 14 | npm install reflect-metadata
|
9 | 15 | ```
|
10 | 16 |
|
| 17 | +## Usage |
| 18 | + |
| 19 | +### ES Modules in NodeJS/Browser, TypeScript/Babel, Bundlers |
| 20 | +```ts |
| 21 | +// - Modifies global `Reflect` object (or defines one in ES5 runtimes). |
| 22 | +// - Supports ESM and CommonJS. |
| 23 | +// - Contains internal polyfills for `Map`, `Set`, and `WeakMap` for older runtimes. |
| 24 | +import "reflect-metadata"; |
| 25 | + |
| 26 | +// - Modifies global `Reflect` object (or defines one in ES5 runtimes). |
| 27 | +// - Supports ESM and CommonJS. |
| 28 | +// - Requires runtime support for `"exports"` in `package.json`. |
| 29 | +// - Does not include internal polyfills. |
| 30 | +import "reflect-metadata/lite"; |
| 31 | +``` |
| 32 | + |
| 33 | +### CommonJS |
| 34 | +```ts |
| 35 | +// - Modifies global `Reflect` object (or defines one in ES5 runtimes). |
| 36 | +// - Contains internal polyfills for `Map`, `Set`, and `WeakMap` for older runtimes. |
| 37 | +require("reflect-metadata"); |
| 38 | + |
| 39 | +// - Modifies global `Reflect` object (or defines one in ES5 runtimes). |
| 40 | +// - Requires runtime support for `"exports"` in `package.json`. |
| 41 | +// - Does not include internal polyfills. |
| 42 | +require("reflect-metadata/lite"); |
| 43 | +``` |
| 44 | + |
| 45 | +### In the Browser via `<script>` |
| 46 | +**HTML** |
| 47 | +```html |
| 48 | +<!-- Modifies global `Reflect` object (or defines one in ES5 runtimes). --> |
| 49 | +<!-- Contains internal polyfills for `Map`, `Set`, and `WeakMap` for older runtimes. --> |
| 50 | +<script src="path/to/reflect-metadata/Reflect.js"></script> |
| 51 | + |
| 52 | +<!-- Modifies global `Reflect` object (or defines one in ES5 runtimes). --> |
| 53 | +<!-- Does not include internal polyfills. --> |
| 54 | +<script src="path/to/reflect-metadata/ReflectLite.js"></script> |
| 55 | +``` |
| 56 | + |
| 57 | +**Script** |
| 58 | +```js |
| 59 | +// - Makes types available in your editor. |
| 60 | +/// <reference path="path/to/reflect-metadata/standalone.d.ts" /> |
| 61 | + |
| 62 | +``` |
| 63 | + |
11 | 64 | ## Background
|
12 | 65 |
|
13 | 66 | * Decorators add the ability to augment a class and its members as the class is defined, through a declarative syntax.
|
|
0 commit comments