I have a framework that uses metadata with decorator in TypeScript so I know it is working.
However, today I just found a bizarre basic case that I can't figure out why.
It is reproducible in TS@2.1.5, @2.1.6, and @2.2.0-dev.20170214
The issue can be demo in https://github.com/unional/some-issues/tree/ts-meta-import
Summary of the situation
// Foo.ts
import 'reflect-metadata'
@Reflect.metadata('somekey', 123)
export class Foo { }
Reflect.getMetadata('somekey', Foo) // returns 123
The above code works fine, however if I try to access Foo
in a different file and do the same thing, it doesn't work:
import 'reflect-metadata'
import { Foo } from './Foo'
Reflect.getMetadata('somekey', Foo) // returns undefined
It really shouldn't be the case....
UPDATE: in my framework, I'm using aurelia-metadata
and it seems to work in this case. But the question remains, why this "simple" scenario doesn't work with reflect-metadata
?