Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
87 lines (54 sloc) 1.7 KB
---
id: babel-preset-typescript
title: @babel/preset-typescript
sidebar_label: typescript
---

This preset includes the following plugins:

You will need to specify --extensions ".ts" for @babel/cli & @babel/node cli's to handle .ts files.

Example

In

const x: number = 0;

Out

const x = 0;

Installation

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

Usage

Via .babelrc (Recommended)

.babelrc

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

Via CLI

babel --presets @babel/preset-typescript script.ts

Via Node API

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

Options

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;. Also, isTSX: true requires allExtensions: true

jsxPragma

string, defaults to React.

Replace the function used when compiling JSX expressions.

This is so that we know that the import is not a type import, and should not be removed

allExtensions

boolean, defaults to false.

Indicates that every file should be parsed as TS or TSX (depending on the isTSX option)

allowNamespaces

boolean, uses the default set by @babel/plugin-transform-typescript.

Enables compilation of TypeScript namespaces.

You can read more about configuring preset options here

You can’t perform that action at this time.