Closed arstulke closed 3 years ago
Nice catch!
I looked at the issue and it appears that the IIFE in Reflect.ts
that's responsible for initializing the global Reflect
object was not included in the bundles generated by deno bundle
. I moved it outside the namespace declaration and now it works for me.
Could you try to create and run a bundle with the following code? If it works, I'll merge my changes in #2 and release a new version with the fixes.
import { Reflect } from "https://raw.githubusercontent.com/cmd-johnson/deno-reflect-metadata/bugfix/deno-bundle/mod.ts";
// deno-lint-ignore no-explicit-any
type Constructor<T = unknown> = new (...args: any[]) => T;
function decorator<T>(_: Constructor<T>): void {}
@decorator
class Example {
constructor(a: string, b: number, c: Example) {}
}
console.log(Reflect.getMetadata("design:paramtypes", Example));
Your fix works for your code snippet, my test steps above and for my project. Thank you for fixing this bug so quickly.
Problem
When I try to use the Metadata Reflection API and bundle my typescript, I get a runtime error. I use your dependency injector lib and when I bundle and run my app it crashes with the following error:
Steps for reproducing
Print deno version:
deno --version
Create the tsconfig.json (from your README.md):
Bundle your example.ts:
deno bundle -c tsconfig.json https://deno.land/x/reflect_metadata@v0.1.12/example.ts example.ts
Execute the bundle:
deno run -c tsconfig.json example.ts
Actual result
The result is the following runtime error:
Through my initial analysis, I was able to determine that this error occurs because the variables
_dec
and_dec1
are undefined. This is the case because the functionReflect.metadata
does not exist.Expected result
My expected result was the same result as in your README:
deno run -c tsconfig.json https://deno.land/x/reflect_metadata@v0.1.12/example.ts
[ [Function: String], [Function: Number], [Function: Example] ]
Question
What changes are required to use the Metadata Reflection API in bundles?