Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cmd-johnson/deno-reflect-metadata
A Deno-compatible copy of the TypeScript Metadata Reflection API my Microsoft
https://github.com/cmd-johnson/deno-reflect-metadata
deno reflect-metadata typescript
Last synced: 3 months ago
JSON representation
A Deno-compatible copy of the TypeScript Metadata Reflection API my Microsoft
- Host: GitHub
- URL: https://github.com/cmd-johnson/deno-reflect-metadata
- Owner: cmd-johnson
- License: apache-2.0
- Created: 2020-10-14T07:33:29.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2022-06-24T11:20:10.000Z (over 2 years ago)
- Last Synced: 2024-09-17T15:17:40.200Z (3 months ago)
- Topics: deno, reflect-metadata, typescript
- Language: TypeScript
- Homepage:
- Size: 31.3 KB
- Stars: 11
- Watchers: 4
- Forks: 4
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Metadata Reflection API for Deno
This is a direct copy of the [Metadata Reflection API by Microsoft](https://github.com/rbuckton/reflect-metadata) with [slight changes](https://github.com/cmd-johnson/deno-reflect-metadata/commit/a39666813eb7e8b38fe563f275085b60f044af7e) to make it usable in Deno.
Check out the [Source Repository](https://github.com/rbuckton/reflect-metadata) for more details.
## Example usage
```ts
import { Reflect } from "https://deno.land/x/[email protected]/mod.ts";// deno-lint-ignore no-explicit-any
type Constructor = new (...args: any[]) => T;function decorator(_: Constructor): void {}
@decorator
class Example {
constructor(a: string, b: number, c: Example) {}
}console.log(Reflect.getMetadata("design:paramtypes", Example));
// "[ [Function: String], [Function: Number], [Function: Example] ]"
```The decorator is required for the TypeScript compiler to generate metadata for the Example class.
If you don't put a decorator on the Example class, the call to `getMetadata` will return `undefined`.> Remember to always add a `tsconfig.json` file with the following content and running your code using `deno run -c tsconfig.json your_code.ts` or decorators and reflection will not work!
```json
{
"compilerOptions": {
"experimentalDecorators": true,
"emitDecoratorMetadata": true
}
}
```