Babel Preset for TypeScript Proposals

4.0.0 · active · verified Sun Apr 19

The `babel-preset-proposal-typescript` (currently v4.0.0) is a Babel preset designed to enable experimental ECMAScript proposals in TypeScript projects that TypeScript itself does not yet natively support. This includes features like async do expressions, record and tuple, pipeline operator, and more, allowing developers to utilize cutting-edge syntax while still leveraging TypeScript's type-checking capabilities for standard features. The preset maintains an active development pace, with major versions typically aligned with updates to its core peer dependencies: `@babel/core` (currently `^7.23.0`) and `typescript` (currently `^5.3.0`). Its primary differentiator is its focused scope: it specifically fills the gap for proposals that the TypeScript team explicitly postpones or chooses not to implement, avoiding redundant transformations with `@babel/preset-typescript` or other standard presets.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to configure Babel with `babel-preset-proposal-typescript` to compile TypeScript code utilizing experimental ECMAScript proposals like `do expressions`, `record and tuple`, and `pipeline operator`.

{
  "plugins": [
    // Ensure decorators are enabled if you use them, and are correctly configured.
    // Babel's order matters: proposals before official features.
  ],
  "presets": [
    ["@babel/preset-env", { "targets": { "node": "current" } }],
    "@babel/preset-typescript",
    "babel-preset-proposal-typescript"
  ]
}
// Example index.ts
async function runDoExpression() {
  const result = await do {
    let x = 10;
    if (x > 5) {
      await Promise.resolve(x * 2);
    } else {
      x * 3;
    }
  };
  console.log('Do expression result:', result);
}

runDoExpression();

const tuple: [string, number] = #['hello', 123];
console.log('Tuple element:', tuple[0]);

function pipelineExample(value: number) {
  return value
    |> ((x) => x * 2)
    |> ((x) => x + 1);
}
console.log('Pipeline result:', pipelineExample(5));

// package.json script
// "scripts": {
//   "build": "babel src/index.ts --out-dir dist --extensions \".ts\""
// }

view raw JSON →