Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reflect.getMetadata is not a function #44

Open
kesemdavid opened this issue Sep 16, 2016 · 6 comments
Open

Reflect.getMetadata is not a function #44

kesemdavid opened this issue Sep 16, 2016 · 6 comments

Comments

@kesemdavid
Copy link

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
Copy link

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
Copy link

Davy-F commented Oct 28, 2016

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
Copy link

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

@httpdigest
Copy link

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
Copy link

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

@schtauffen
Copy link

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"
    ]
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants