Skip to main content

@babel/plugin-transform-flow-strip-types

NOTE: This plugin is included in @babel/preset-flow

Example

In

JavaScript
function foo(one: any, two: number, three?): string {}

Out

JavaScript
function foo(one, two, three) {}

Installation

npm install --save-dev @babel/plugin-transform-flow-strip-types

Usage

babel.config.json
{
"plugins": ["@babel/plugin-transform-flow-strip-types"]
}

Via CLI

Shell
babel --plugins @babel/plugin-transform-flow-strip-types script.js

Via Node API

JavaScript
require("@babel/core").transformSync("code", {
plugins: ["@babel/plugin-transform-flow-strip-types"],
});

Options

all

boolean, defaults to false.

Flow will only parse Flow-specific features if a @flow pragma is present atop the file, or the all option is set inside the .flowconfig.

If you are using the all option in your Flow config, be sure to set this option to true to get matching behavior.

For example, without either of the above, the following call expression with a type argument:

f<T>(e)

Would get parsed as a nested binary expression:

JavaScript
f < T > e;

requireDirective

boolean, defaults to false.

Setting this to true will only strip annotations and declarations from files that contain the // @flow directive. It will also throw errors for any Flow annotations found in files without the directive.

allowDeclareFields

boolean, defaults to false

Added in: v7.9.0

NOTE: This will be enabled by default in Babel 8

When enabled, type-only class fields are only removed if they are prefixed with the declare modifier:

JavaScript
class A {
declare foo: string; // Removed
bar: string; // Initialized to undefined
}

You can read more about configuring plugin options here