Skip to content

Latest commit

 

History

History
67 lines (44 loc) · 1.94 KB

plugin-syntax-typescript.md

File metadata and controls

67 lines (44 loc) · 1.94 KB
id title sidebar_label
babel-plugin-syntax-typescript
@babel/plugin-syntax-typescript
syntax-typescript

:::note

Syntax only

Using this plugin directly only enables Babel to parse this syntax. If you want to remove TypeScript syntax then use the typescript plugin or typescript preset to both parse and transform this syntax. :::

npm install --save-dev @babel/plugin-syntax-typescript

Usage

With a configuration file (Recommended)

{
  "plugins": ["@babel/plugin-syntax-typescript"]
}

Via CLI

babel --plugins @babel/plugin-syntax-typescript script.js

Via Node API

require("@babel/core").transformSync("code", {
  plugins: ["@babel/plugin-syntax-typescript"],
});

Options

disallowAmbiguousJSXLike

boolean, defaults to false

Added in: v7.16.0

Even when JSX parsing is not enabled, this option disallows using syntax that would be ambiguous with JSX (<X> y type assertions and <X>() => {} type arguments). It matches the tsc behavior when parsing .mts and .mjs files.

dts

boolean, defaults to false

Added in: v7.20.0

This option will enable parsing within a TypeScript ambient context, where certain syntax have different rules (like .d.ts files and inside declare module blocks). Please see Official Handbook and TypeScript Deep Dive for more information about ambient contexts.

isTSX

boolean, defaults to false.

Forcibly enables jsx parsing. Otherwise angle brackets will be treated as typescript's legacy type assertion var foo = <string>bar;

:::tip You can read more about configuring plugin options here :::