About TypeScript to JavaScript Converter
Paste TypeScript, or open a .ts or .tsx file, and get the same code without its types: annotations, interfaces, type aliases, generics, overloads and type-only imports are removed, while enums and constructor parameter properties are compiled into the plain JavaScript they stand for.
The types are removed, not checked: code with a type error converts just as well, so this is not a replacement for the TypeScript compiler. Newer syntax such as optional chaining, class fields or private methods is left exactly as written; nothing is rewritten for an older ECMAScript version. Choose whether JSX is kept or compiled for React, and whether imports stay as ES modules or become require calls.
How it works
- The code is parsed in a background worker, so a long file never freezes the page and an edit cancels a conversion that is out of date.
- Everything that exists only for the type checker is removed. Enums become objects, parameter properties become assignments in the constructor, and import x = require(…) and export = become CommonJS.
- With a JSX option chosen, the file is read as TSX: JSX is either kept, compiled for the React automatic runtime, or compiled to calls of an element function you name.
- With CommonJS chosen, import and export statements become require calls and assignments to exports.
- As written keeps each statement on its original line, so line numbers in error messages still match; Reformatted lays the JavaScript out again in a consistent style, keeping the quote style your code uses most.
Questions
Does it check my types?
No. Types are removed without being checked, so code that the TypeScript compiler would reject converts all the same. Run the compiler to find type errors.
Can it output older JavaScript, such as ES5?
No. Syntax is left as written: optional chaining, nullish coalescing, class fields, private members and the like come out unchanged. The output needs an engine that supports what the input uses, as current browsers and Node.js do.
What happens to enums, namespaces and decorators?
An enum becomes an object, with a reverse mapping for numeric members; a const enum becomes an ordinary enum and its uses are not inlined. Namespaces that hold only types, or are declared with declare, are removed, but one that holds values is refused, because it cannot be compiled here. Decorators are left as written, and decorators on parameters are not accepted.
Why did an import disappear?
An import whose names are used only as types has nothing left to import once the types are gone, so it is removed, as the TypeScript compiler does by default. Turn on Keep imports used only as types to keep it, for example when the module is imported for its side effects.
Where does a syntax error point?
To the line and column where reading stopped, counting each character, emoji included, as one column. If the file contains JSX, choose a JSX option, because with JSX set to None the file is read as plain TypeScript.
Everything you enter here is processed in this browser tab. Nothing is uploaded, logged or shared. How privacy works here.