rbuckton / reflect-metadata

Prototype for a Metadata Reflection API for ECMAScript
https://rbuckton.github.io/reflect-metadata
Apache License 2.0
3.19k stars 183 forks source link

Reflect.getMetadata is not a function #44

Open kesemdavid opened 8 years ago

kesemdavid commented 8 years ago

So i have update to the latest RC7 of angular2 and now im getting this error :

Reflect.getMetadata is not a function

What can I do to fix this issue, I'm using the 0.1.2 version. (Also tried with the latest 0.1.8)

Thanks in advance!

blowback commented 7 years ago

I had a similar problem upgrading to angular2 2.0.1 from 2.0.0-rc5. At the same time I upgraded angular-cli from 1.0.0-beta.11-webpack.2 to 1.0.0-beta.15.

when running 'ng init' i was a bit prescriptive in what I allowed angular-cli to update: one of the things it wanted to change was main.ts, adding the line import './polyfills.ts'; to the top of main.ts fixed it for me.

Davy-F commented 7 years ago

I'm also getting this error. On the latest version of Angular and not using angular-cli. In my package.json I have: "reflect-metadata": "^0.1.8",

I thought polyfills were no longer used?

BergerLand commented 7 years ago

Any update on this? I too am having this problem.

httpdigest commented 6 years ago

I wanted to use reflect-metadata without Angular just to include it in a project with run-time type introspection of class properties, so I tried a very simple example with tsconfig.json target=ES2017, module=2015 and a simple test.ts:

import 'reflect-metadata';
function logType(target : any, key : string) {
   var t = Reflect.getMetadata("design:type", target, key);
   console.log(`${key} type: ${t.name}`);
}
export class Demo {
  @logType
  test: Date;
}
console.log(Reflect.getMetadata('design:type', new Demo(), "test"));

And it complains: error TS2339: Property 'getMetadata' does not exist on type 'typeof Reflect'. The reason is that TypeScript thinks that Reflect means the lib.es2015.reflect.d.ts (because ES2015 also defines Reflect symbol on global namespace). How do I solve this?

bashleigh commented 6 years ago

I added the reflect-metadata types and that resolved my problem yarn add --dev @types/reflect-metadata

schtauffen commented 5 years ago

I ran into this problem inside a lib. I resolved it by following @bashleigh's example and installing the types,

npm i --save @types/reflect-metadata

But also had to add an entry within tsconfig.lib.json:

{
  "extends": "../../tsconfig.json",
  "compilerOptions": {
    ...
    "types": [
      "reflect-metadata"
    ]
  }
}