Babel 中文文档
  • 印记中文
  • 文档
  • 配置
  • 试用
  • 视频
  • 博客
  • 赞助
  • 团队
  • GitHub

›预设

指南

  • 什么是 Babel?
  • 使用指南
  • 配置 Babel
  • 学习 ES2015
  • 升级至 Babel 7

配置参考

  • 配置文件
  • Config Options
  • 预设
  • 插件
  • 插件列表
  • Compiler assumptions

预设

  • @babel/preset-env
  • @babel/preset-react
  • @babel/preset-typescript
  • @babel/preset-flow

杂项

  • 路线图
  • 注意事项
  • 新增特性时间轴
  • FAQ
  • 编辑器

集成包

  • @babel/cli
  • @babel/polyfill
  • @babel/plugin-transform-runtime
  • @babel/register
  • @babel/standalone

工具包

  • @babel/parser
  • @babel/core
  • @babel/generator
  • @babel/code-frame
  • @babel/runtime
  • @babel/template
  • @babel/traverse
  • @babel/types

帮助工具包

  • helper-compilation-targets
  • helper-module-imports
Edit

@babel/preset-flow

This preset is recommended if you use Flow, a static type checker for JavaScript code. It includes the following plugins:

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

Example

In

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

Out

function foo(one, two, three) {}

Installation

npm install --save-dev @babel/preset-flow

Usage

With a configuration file (Recommended)

{
  "presets": ["@babel/preset-flow"]
}

Via CLI

babel --presets @babel/preset-flow script.js

Via Node API

require("@babel/core").transformSync("code", {
  presets: ["@babel/preset-flow"],
});

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 set, the following call expression with a type argument:

f<T>(e)

Would get parsed as a nested binary expression:

f < T > e;

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:

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

You can read more about configuring preset options here

← @babel/preset-typescript路线图 →
  • Example
  • Installation
  • Usage
    • With a configuration file (Recommended)
    • Via CLI
    • Via Node API
  • Options
    • all
    • allowDeclareFields
Babel 中文文档
文档
学习 ES2015
社区
视频用户Stack OverflowSlack 频道Twitter
更多
博客GitHub 组织GitHub 仓库Website 仓库旧版网址 6.x旧版网址 5.x