Skip to main content

@babel/plugin-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​

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

Via CLI​

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

Via Node API​

JavaScript
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