UNPKG

1.33 kBMarkdownView Raw
1# babel-plugin-transform-flow-comments
2
3> Turn flow type annotations into comments.
4
5You should be able to use this plugin instead of `babel-plugin-flow-strip-types` to preserve the `/* @flow */` directive and still use flow.
6
7[Flow Comments Blog Post](http://flowtype.org/blog/2015/02/20/Flow-Comments.html)
8
9## Example
10
11**In**
12
13```javascript
14function foo(bar?) {}
15function foo2(bar?: string) {}
16function foo(x: number): string {}
17type B = {
18 name: string;
19};
20export type GraphQLFormattedError = number;
21import type A, { B, C } from './types';
22import typeof D, { E, F } from './types';
23```
24
25**Out**
26
27```javascript
28"use strict";
29
30function foo(bar /*:: ?*/) {}
31function foo2(bar /*:: ?: string*/) {}
32function foo(x /*: number*/) /*: string*/ {}
33/*:: type B = {
34 name: string;
35};*/
36/*:: export type GraphQLFormattedError = number;*/
37/*:: import type A, { B, C } from './types';*/
38/*:: import typeof D, { E, F } from './types';*/
39```
40
41## Installation
42
43```sh
44npm install --save-dev babel-plugin-transform-flow-comments
45```
46
47## Usage
48
49### Via `.babelrc` (Recommended)
50
51**.babelrc**
52
53```json
54{
55 "plugins": ["transform-flow-comments"]
56}
57```
58
59### Via CLI
60
61```sh
62babel --plugins transform-flow-comments script.js
63```
64
65### Via Node API
66
67```javascript
68require("babel-core").transform("code", {
69 plugins: ["transform-flow-comments"]
70});
71```