So I have a TypeScript project I am working on and I want to make use of the reflect-metadata package. I am a little confused about the correct way of importing this. It was my understanding that this only needed to be imported once in your "main" file. So in my case I have an app.ts in which I import reflect-metadata as the very first thing:
import 'reflect-metadata';
import ReflectionClass from '@src/Reflection/ReflectionClass';
...
ReflectionClass
then in turn imports another class that eventually calls Reflect.getMetadata()
. However, this fails with error
error TS2339: Property 'getMetadata' does not exist on type 'typeof Reflect'.
Only when I import reflect-metadata explicitly in the relevant file does the error disappear. Is this the correct way to do this? In other words, do I need to import reflect-metadata in each file that uses it as opposed to a global, one time import in your main file?