Online TypeScript Compiler

Compile TypeScript 5.6 to JavaScript and run it in your browser. See the console output and the generated JavaScript side by side.

TypeScript 5.6 · Runs in your browser, so your code never reaches our servers.
main.tsTypeScript
Output

            
        
Ctrl/⌘ + Enter to run

How to use the online TypeScript compiler

  1. Write or paste TypeScript into the editor, or start from the example (Reset example restores it).
  2. Press Run or use Ctrl + Enter (⌘ + Enter on a Mac).
  3. Your code is compiled to JavaScript. If the compiler finds a syntax error, it is listed with its TS error code, line and column, and nothing runs.
  4. If compilation succeeds, the JavaScript runs. console.log output appears in the Output panel, and you can open Generated JavaScript below the editor to see exactly what the compiler produced.
  5. Choose a time limit of 5, 15 or 60 seconds, or press Stop to end a run early.

On the first run the page downloads the official TypeScript compiler, about 3 MB. Your browser caches it, so later runs start quickly.

Compilation and execution both happen in a Web Worker in your browser. Your code is not uploaded and is not stored on our servers. The editor saves your last code in your browser's local storage, and in no other place.

What's supported

This page uses TypeScript 5.6, the official Microsoft compiler. It targets ES2022 and runs the result on your browser's JavaScript engine.

  • All TypeScript syntax: type annotations, interfaces, type aliases, generics, union and intersection types, enums, access modifiers, satisfies, as const and more.
  • Modern JavaScript output with classes, async/await and optional chaining left intact.
  • Top-level await, timers and promises, just like the online JavaScript compiler.

Limitations:

  • Transpile-only. The compiler removes types and reports syntax errors, but it does not perform full type-checking. Code like const n: number = "text" compiles and runs. Use tsc --noEmit or your editor when you need semantic type errors.
  • No DOM: the code runs in a worker, so document and window are unavailable.
  • No imports: npm packages, import statements and Node.js APIs cannot be used.

TypeScript quick reference

type Shape =
  | { kind: "circle"; r: number }
  | { kind: "rect"; w: number; h: number };

function area(s: Shape): number {
  switch (s.kind) {
    case "circle": return Math.PI * s.r ** 2;
    case "rect":   return s.w * s.h;
  }
}

function first<T>(items: T[]): T | undefined {
  return items[0];
}

const shapes: Shape[] = [{ kind: "circle", r: 1 }, { kind: "rect", w: 2, h: 3 }];
console.log(shapes.map(area));   // [3.141592653589793, 6]
console.log(first(shapes)?.kind);
ConceptSyntax
Typed variablelet count: number = 0;
Interfaceinterface User { id: number; name?: string }
Union typetype Id = string | number;
Generic functionfunction wrap<T>(v: T): T[] { return [v]; }
Readonly arrayconst xs: readonly number[] = [1, 2];
Enumenum Dir { Up, Down }

Tips

  • Open Generated JavaScript to learn how features like enums, parameter properties and class fields compile. It is a quick way to understand what TypeScript does at runtime.
  • Remember that types disappear at runtime. To validate data from outside (such as parsed JSON), write runtime checks or type guards like function isUser(x: unknown): x is User.
  • Need to tidy the output before you copy it into a project? Paste it into the JavaScript formatter.
Tip: An error such as TS1005: ';' expected means the code could not be parsed. Fix the line and column shown in the output, then run again.

Frequently asked questions

Does this check my types?

No. It uses the compiler's transpile mode, which reports syntax errors only. That keeps it fast and lightweight, but type mismatches are not reported. For full checking, run tsc locally or use an editor with the TypeScript language service.

What is the difference between TypeScript and JavaScript?

TypeScript is JavaScript with optional static types. Browsers cannot run TypeScript directly, so it is first compiled to plain JavaScript by removing the types and lowering a few TypeScript-only features, such as enums. You can see the result of that step on this page.

Which TypeScript version is used?

TypeScript 5.6, with ES2022 as the output target.

Can I import libraries?

No. Each run compiles and executes a single file without module resolution, so import statements and npm packages are not supported. See all our developer tools for related utilities.

Copied to clipboard