How to Convert TypeScript to JavaScript: Strip Types or Compile

See what happens when TypeScript becomes JavaScript, which features need real code (enums, parameter properties) and how to convert with tsc or in a browser.

Updated September 29, 2026 5 min read

Use the free TypeScript to JavaScriptStrip types from TS and TSX to get clean, runnable JavaScript

You find the perfect snippet in a TypeScript project, but the page you need it for is a plain JavaScript file, a CMS script block or a legacy build with no TypeScript support. Or a colleague on a JavaScript-only codebase asks for "the same function without the types". Deleting annotations by hand looks easy until you meet a generic, an enum or a constructor(private readonly name: string).

This guide explains what really changes when TypeScript turns into JavaScript, which constructs need more than deletion, and the fastest ways to do the conversion for one file or a whole project.

Type stripping versus compiling

Converting TypeScript to JavaScript involves two different jobs that people often mix up:

  1. Removing the type layer. Annotations (: string), interfaces, type aliases, generics (<T>), as casts, satisfies, ! non-null assertions and import type lines are erased. They have no runtime meaning, so removing them does not change behaviour.
  2. Downlevelling modern syntax. Optionally rewriting newer JavaScript (optional chaining, class fields) into older syntax for old browsers. This is a separate choice and has nothing to do with types.

A handful of TypeScript features are not pure types and generate real JavaScript when converted:

TypeScript feature JavaScript output
enum Currency { EUR = "EUR" } An object built by a small function
constructor(private owner: string) A normal parameter plus this.owner = owner
namespace Utils { ... } An object wrapped in a function
Decorators (depending on settings) Helper calls around the class

Everything else simply disappears.

A worked example

This TypeScript:

interface Invoice {
  id: string;
  amount: number;
  paid?: boolean;
}

enum Currency {
  EUR = "EUR",
  USD = "USD",
}

export function formatTotal(inv: Invoice, currency: Currency = Currency.EUR): string {
  return `${inv.id}: ${inv.amount.toFixed(2)} ${currency}`;
}

export class Ledger {
  constructor(private readonly owner: string) {}
  describe(): string {
    return `Ledger for ${this.owner}`;
  }
}

becomes this JavaScript (as emitted by tsc targeting ES2022):

var Currency;
(function (Currency) {
    Currency["EUR"] = "EUR";
    Currency["USD"] = "USD";
})(Currency || (Currency = {}));
export function formatTotal(inv, currency = Currency.EUR) {
    return `${inv.id}: ${inv.amount.toFixed(2)} ${currency}`;
}
export class Ledger {
    owner;
    constructor(owner) {
        this.owner = owner;
    }
    describe() {
        return `Ledger for ${this.owner}`;
    }
}

The interface is gone, the enum is now an object, and the private readonly parameter became an assignment. private and readonly are compile-time checks only; in the JavaScript output, owner is an ordinary public property.

Convert a file in your browser

The TypeScript to JavaScript converter strips types locally in your browser, with no upload and no project setup.

  1. Open TypeScript to JavaScript and paste your code, use Open file for a .ts or .tsx file, or click Load sample.
  2. Set File type. Choose .tsx (TypeScript + JSX) for React components. Choose .ts (allows value casts) for plain TypeScript that uses old-style angle-bracket casts, which would be misread as JSX in a .tsx file.
  3. For TSX, pick JSX output: Keep JSX to get a .jsx file, react/jsx-runtime for the modern automatic runtime, or React.createElement for the classic transform.
  4. Switch on Convert imports to CommonJS if the target uses require() instead of import.
  5. Keep Tidy with Prettier on for readable output with consistent spacing.
  6. Copy the JavaScript or Download it.

The tool removes types but does not check them: code with type errors converts without complaint. Enums and constructor parameter properties are turned into plain JavaScript, while modern syntax such as ?. and ?? is kept as written, so the output targets ES2020-level environments. If you need older syntax, run the result through a transpiler such as Babel afterwards.

Converting a whole project with tsc

For more than a few files, use the TypeScript compiler, which also type-checks:

# Compile using the project's tsconfig.json
npx tsc

# Compile into a separate folder
npx tsc --outDir dist

# Type-check only, emit nothing
npx tsc --noEmit

If your goal is to leave TypeScript behind permanently, compile with a modern target (for example ES2022) and module set to ESNext, so the output stays close to your source, then format it with Prettier. Expect to review comments and blank lines: the compiler keeps comments by default but may reflow code, and hand-written JSDoc can replace the lost type information.

Running TypeScript without converting at all

Sometimes you do not need a JavaScript file. Build tools such as Vite, esbuild and SWC strip types on the fly, and recent Node.js releases can run .ts files directly by erasing types (introduced behind a flag in Node.js 22.6 and enabled by default in later versions; check the documentation for your version). Node's built-in stripping does not support enums or parameter properties without an extra flag, and TypeScript 5.8's erasableSyntaxOnly option exists to flag exactly those constructs.

Pitfalls to watch for

JSX versus angle-bracket casts

<Invoice>data is a cast in a .ts file but looks like a JSX element in .tsx. If conversion fails with an unexpected token near a <, check the File type setting, or rewrite the cast as data as Invoice.

const enum and cross-file enums

Type strippers work one file at a time, so they cannot inline a const enum imported from another module. Plain enums are safer, or replace them with a const object plus a union type.

Type-only imports

An import used only as a type is removed. If a module was imported for its side effects, keep it as import "./setup"; so it stays in the output.

Lost documentation

Types were documentation. When the JavaScript is meant to live on, add JSDoc comments (/** @param {string} id */) to the public functions so editors can still offer hints.

If you need the opposite direction for data, JSON to TypeScript generates interfaces from sample JSON. To tidy other code afterwards, the Code Formatter and JavaScript Formatter help, and HTML to JSX converts markup for React components.

Frequently asked questions

Does converting TypeScript to JavaScript change how the code runs?

Removing annotations, interfaces and generics does not change behaviour. Enums, namespaces and parameter properties become equivalent JavaScript, so the result behaves the same as the compiled TypeScript would.

Does the converter check my types?

No. It only removes them. Run tsc --noEmit in your project if you want type errors reported.

How do I convert TSX to JSX?

Set File type to TSX and choose Keep JSX as the JSX output. Types are removed and the JSX markup is left untouched, ready to save as a .jsx file.

Can I convert JavaScript back to TypeScript the same way?

Not automatically. Renaming a .js file to .ts is valid, but adding meaningful types is manual work, helped by the compiler's errors and your editor's inferred types.

Why is my private field public in the JavaScript output?

TypeScript's private keyword is a compile-time check only. For privacy that is enforced at runtime, use JavaScript's own #field syntax, which the converter keeps as written.

Try it now: TypeScript to JavaScript

Loading tool…