@babel/plugin-transform-flow-strip-types
此插件包含在 @babel/preset-flow
中
¥This plugin is included in @babel/preset-flow
示例
¥Example
输入
¥In
function foo(one: any, two: number, three?): string {}
输出
¥Out
function foo(one, two, three) {}
安装
¥Installation
- npm
- Yarn
- pnpm
npm install --save-dev @babel/plugin-transform-flow-strip-types
yarn add --dev @babel/plugin-transform-flow-strip-types
pnpm add --save-dev @babel/plugin-transform-flow-strip-types
用法
¥Usage
使用配置文件(推荐)
¥With a configuration file (Recommended)
{
"plugins": ["@babel/plugin-transform-flow-strip-types"]
}
通过 CLI
¥Via CLI
babel --plugins @babel/plugin-transform-flow-strip-types script.js
通过 Node API
¥Via Node API
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:
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:
class A {
declare foo: string; // Removed
bar: string; // Initialized to undefined
}