0.4.0 • Published 8 years ago

babel-plugin-type-metadata v0.4.0

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

babel-plugin-type-metadata Build Status Coverage Status

This plugin generates code to identify Flow types at runtime via metadata.

Usage

If you run the plugin on the following input

/* @flow */

class MyClass {
  stringMethod(): string {
    return 'string';
  }
}

it will create add the following metadata:

Reflect.defineMetadata('typeof', {
  kind: 'method',
  returns: {
    type: String
  },
  parameters: []
}, MyClass, 'stringMethod');

Important: Since the reflection API is still just a proposal at this time, you'll need a polyfill like core-js.

Get Started

Install the plugin:

npm install babel-plugin-type-metadata --save-dev

And add the additional step to your .babelrc:

{
  "plugins": [
    "babel-plugin-syntax-flow",
    "babel-plugin-type-metadata"
  ]
}