How to import/use Reflect in typescript
you have to import the type declarations together with the (js) library
npm install reflect-metadata -D
inside your .ts file:
import "reflect-metadata";
As of today, @types/reflect-metadata
is deprecated since reflect-metadata
includes already its own typings.
So, to use them you just need to import the library (Uses the global scope). That's it.
Install it:
npm install reflect-metadata --save
Import it:
import 'reflect-metadata';
Typescript uses a Module loading paradigm that's a bit different than that of JavaScript.
Say you have a module Modulus
that defines three classes A
, B
and C
.
import { A } from "Modulus"
will import the class (or function) A
from the module Modulus
and make it available in your current module. If Typescript finds no export named A
in Modulus
and error will be thrown.
// Equivalent to the following in JavaScript:
// var ModuleNameOfYourChoice = require("Modulus")
import * as ModuleNameOfYourChoice from "Modulus"
will import all the exports declared within Modulus
and make them available to the current module under the name ModuleNameOfYourChoice
.
For your code, you need all the exports defined in reflect-metadata
module and thus need to import it as
import * as Reflect from "reflect-metadata"
All the best!
Typescript documentation: http://www.typescriptlang.org/docs/handbook/modules.html#import