Babel Plugin for TypeScript Transformation

7.0.0-alpha.19 · active · verified Sun Apr 19

This package, `@babel/plugin-transform-typescript`, is a core Babel plugin designed to strip TypeScript type annotations from code, transforming it into standard ECMAScript. It operates solely on the syntax level and does not perform any type-checking; users must integrate the TypeScript compiler (tsc) separately for type validation. The current stable major version is 7 (e.g., v7.29.2 as of March 2026), with active development ongoing for Babel 8, which is currently in release candidate stages (e.g., v8.0.0-rc.3). Babel maintains a frequent release cadence for patch versions and rolls out minor/major updates periodically. A key differentiator is its focus on pure syntax transformation, which makes it faster than a full TypeScript compilation but also means it explicitly does not support TypeScript-specific features like `namespace` declarations, `const enum`s, or the legacy `export =` and `import =` syntax, as these features require type information for meaningful transformation.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to install and configure `@babel/plugin-transform-typescript` to transpile a TypeScript file containing interfaces, type-only imports, and functions into standard JavaScript using the Babel CLI.

/* file: package.json */
{
  "name": "my-ts-project",
  "version": "1.0.0",
  "scripts": {
    "build": "babel src --out-dir dist --extensions \".ts,.tsx\""
  },
  "devDependencies": {
    "@babel/cli": "^7.0.0",
    "@babel/core": "^7.0.0",
    "@babel/plugin-transform-typescript": "^7.0.0"
  }
}

/* file: babel.config.js */
module.exports = {
  plugins: [
    "@babel/plugin-transform-typescript",
    // If you use React and JSX, also add:
    // "@babel/plugin-transform-react-jsx"
  ]
};

/* file: src/index.ts */
interface User {
  id: number;
  name: string;
  email?: string;
}

const user: User = {
  id: 1,
  name: "Alice",
  email: "alice@example.com"
};

function greet(person: User): string {
  return `Hello, ${person.name}! Your ID is ${person.id}.`;
}

console.log(greet(user));

// Example of a type-only import (will be stripped by Babel)
import type { UtilityType } from './types';

// A type declaration
type UtilityType = { timestamp: number };
const data: UtilityType = { timestamp: Date.now() };
console.log(`Current data timestamp: ${data.timestamp}`);

/* To run this example: */
/* 1. Create the files above */
/* 2. `npm install` */
/* 3. `npm run build` */
/* 4. `node dist/index.js` */

view raw JSON →