Babel
  • Docs
  • Setup
  • Try it out
  • Videos
  • Blog
  • Donate
  • Team
  • GitHub

›Presets

Guides

  • What is Babel?
  • Usage Guide
  • Configure Babel
  • Learn ES2015
  • Upgrade to Babel 7
  • Upgrade to Babel 7 (API)

General

  • Editors
  • Plugins
  • Presets
  • Caveats
  • FAQ
  • Roadmap

Usage

  • Options
  • Config Files
  • cli
  • polyfill
  • transform-runtime
  • register

Presets

  • env
  • flow
  • react
  • typescript

Tooling

  • parser
  • core
  • generator
  • code-frame
  • helpers
  • runtime
  • template
  • traverse
  • types
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").transform("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

← envreact →
  • Example
  • Installation
  • Usage
    • With a configuration file (Recommended)
    • Via CLI
    • Via Node API
  • Options
    • all
    • allowDeclareFields
Babel
Docs
Learn ES2015
Community
VideosUser ShowcaseStack OverflowSlack ChannelTwitter
More
BlogGitHub OrgGitHub RepoWebsite RepoOld 6.x SiteOld 5.x Site