Skip to main content

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

信息

此插件包含在 @babel/preset-flow

¥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

¥With a configuration file (Recommended)

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

通过 CLI

¥Via CLI

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

通过 Node API

¥Via Node API

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

选项

¥Options

all

boolean,默认为 false

¥boolean, defaults to false.

如果文件顶部存在 @flow pragma,或者 all 选项 设置在 .flowconfig 中,Flow 只会解析 Flow 特定的功能。

¥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.

如果你在 Flow 配置中使用 all 选项,请务必将此选项设置为 true 以获得匹配的行为。

¥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,默认为 false

¥boolean, defaults to false.

将此设置为 true 只会从包含 // @flow 指令的文件中删除注释和声明。对于在没有该指令的文件中找到的任何 Flow 注释,它也会引发错误。

¥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,默认为 false

¥boolean, defaults to false

添加于:v7.9.0

¥Added in: v7.9.0

注意

这将在 Babel 8 中默认启用

¥This will be enabled by default in Babel 8

启用后,仅类型的类字段仅在以 declare 修饰符为前缀时才会被删除:

¥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