How to use the online TypeScript compiler
- Write or paste TypeScript into the editor, or start from the example (Reset example restores it).
- Press Run or use Ctrl + Enter (⌘ + Enter on a Mac).
- Your code is compiled to JavaScript. If the compiler finds a syntax error, it is listed with its
TSerror code, line and column, and nothing runs. - If compilation succeeds, the JavaScript runs.
console.logoutput appears in the Output panel, and you can open Generated JavaScript below the editor to see exactly what the compiler produced. - 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 constand 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. Usetsc --noEmitor your editor when you need semantic type errors. - No DOM: the code runs in a worker, so
documentandwindoware unavailable. - No imports: npm packages,
importstatements 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);
| Concept | Syntax |
|---|---|
| Typed variable | let count: number = 0; |
| Interface | interface User { id: number; name?: string } |
| Union type | type Id = string | number; |
| Generic function | function wrap<T>(v: T): T[] { return [v]; } |
| Readonly array | const xs: readonly number[] = [1, 2]; |
| Enum | enum 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.
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.