Skip to content
UniKit

TypeScript ↔ JavaScript

Turn TypeScript into JavaScript with the bundled TypeScript compiler (target ES5/ES2015/ES2020/ESNext, CommonJS/ESM, optional comment removal) or heuristically infer a TypeScript skeleton from JavaScript (any-typed parameters, interfaces from object literals), showing TS diagnostics with line and column.

Runs in your browserEvery computation happens in your browser — your data never leaves this device.

The compiler comes with the build toolchain; the output is a syntax-only transform (no type checking)

Output

Type some code, then hit Convert
TS diagnostics

What this tool does

  • Turn a chunk of TypeScript into runnable JavaScript: interfaces, type annotations and generic parameters are erased while the structure stays intact.
  • Downgrade syntax for older environments: with ES5, arrow functions become function expressions and template literals become string concatenation; with CommonJS, imports become require and exports.
  • Go the other way and get a TypeScript skeleton from JavaScript: parameters and return values typed any, interfaces generated from object literals, ready to be tightened by hand.
  • Find syntax errors with TS diagnostics, reported as “line X, column Y, code TS1234: message”, faster than running the file in a browser.

Example

Input

interface User { id: number; name: string }

const greet = (user: User, prefix = 'hi'): string => `${prefix} ${user.name}`;

export default greet;

Output

const greet = (user, prefix = 'hi') => `${prefix} ${user.name}`;
export default greet;

This is the default setup (TS → JS, target ES2020, module ESNext): the interface is removed entirely and the parameter and return annotations are stripped, everything else is kept verbatim. Choosing ES5 + CommonJS produces function and exports.default instead. The first conversion waits for the compiler to load.

Frequently asked questions

Is this a type checker? Will it report type errors?

No. The conversion uses transpileModule, a syntax-only transform that reads no other files and infers no types, so “string assigned to number” style errors are not reported. It only surfaces syntax-level problems such as an unclosed bracket.

How accurate is the JS → TS inference?

It is a heuristic skeleton: parameters and return types become any, object literals become interfaces, arrays get element types like string[], and complex values become unknown. It saves the typing, but you still have to refine and verify it by hand.

Why is no return type added to arrow functions?

Annotating a single-parameter arrow function produces the invalid form (x): any => …, so the tool deliberately skips return annotations on arrow functions and shows a note instead. Add one manually when you need it.

Does my code get sent to a server?

No. The TypeScript compiler is bundled with the page and runs in your browser, so the code never leaves your machine. The trade-off is a short wait the first time while the compiler loads.

Which targets and module formats are supported?

Targets are ES5, ES2015, ES2020 and ESNext; modules are ESNext and CommonJS; comments can optionally be removed. The transform is syntax-only — no polyfills are added, so new runtime APIs still have to be provided separately.

Keywords:typescriptjavascripttranspilets to jsjs to tscompileres5commonjs转换编译诊断

Related tools