Please use the original Package deno add npm:reflect-metadata
(https://www.npmjs.com/package/reflect-metadata).
This is a fork of jiawei397/deno-reflect-metadata
This includes a copy of the Metadata Reflection API by Microsoft with slight changes to make it usable in Deno.
Check out the Source Repository for more details.
type ClassConstructor<T = unknown> = new (...args: any[]) => T; function Decorator<T>() { return (_: ClassConstructor<T>): void => {}; } class ClassA {} @Decorator() class ClassB { constructor(a: string, b: number, c: ClassA) {} } const metadata = Reflect.getMetadata('design:paramtypes', ClassB); console.log(metadata?.map((x: ClassConstructor) => x.name).join(', ')); // "String, Number, ClassA"
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 usingdeno run -c tsconfig.json your_code.ts
or decorators and reflection will not work!
{ "compilerOptions": { "experimentalDecorators": true, "emitDecoratorMetadata": true } }
Add Package
deno add jsr:@dx/reflect
Import symbol
import * as reflect from "@dx/reflect";
---- OR ----
Import directly with a jsr specifier
import * as reflect from "jsr:@dx/reflect";