Write TypeScript and run it right here. It is turned into JavaScript and run in your browser — nothing is uploaded.
Ready
// Types are removed before running (no type checking).
interface User {
name: string;
age: number;
}
const users: User[] = [
{ name: "Ada", age: 36 },
{ name: "Linus", age: 21 },
];
for (const user of users) {
console.log(`${user.name} is ${user.age}`);
}
Type the input before you run. Each prompt() call reads the next line.
Output
Press Run or Ctrl+Enter to see the output here.
Runs in your browser with TypeScript → JavaScript (Sucrase 3.35.1). Your code is not sent to a server.
How to run TypeScript code here
Write or paste your TypeScript code into the editor. There is a short example in it to start from.
If your program reads input, type it into the input box first — one value per line.
Press Run or Ctrl+Enter. The output appears next to the editor, with errors shown in red.
How this page runs TypeScript
Runtime: TypeScript → JavaScript (Sucrase 3.35.1)
When you press Run, Sucrase 3.35.1 removes the type annotations in your browser, and the JavaScript that is left runs in a Web Worker exactly as on the JavaScript page. Line numbers stay the same, so an error points at the line you wrote. Interfaces, type aliases, generics, enums, access modifiers, parameter properties and abstract classes are all accepted.
Everything happens on your device. The code you write is never uploaded, logged or stored on a server. Each run stops after 10 seconds and keeps up to 100,000 characters of output, so an endless loop cannot freeze the page.
What is not available
Types are removed, not checked. A type mistake does not stop the program — only a real error at run time does — so use tsc or your own editor when you need full type checking. As with JavaScript, Node.js APIs and npm packages are not available.
TypeScript examples
Open an example in the editor above, change it and run it. Opening an example does not run it.
A generic groupBy function
function groupBy<T, K extends string>(items: T[], key: (item: T) => K): Record<K, T[]> {
const groups = {} as Record<K, T[]>;
for (const item of items) {
(groups[key(item)] ??= []).push(item);
}
return groups;
}
const words = ["apple", "avocado", "banana", "blueberry", "cherry"];
console.log(groupBy(words, (w) => w[0]));
Discriminated unions with switch
type Shape =
| { kind: "circle"; radius: number }
| { kind: "rect"; width: number; height: number };
function area(shape: Shape): number {
switch (shape.kind) {
case "circle":
return Math.PI * shape.radius ** 2;
case "rect":
return shape.width * shape.height;
}
}
const shapes: Shape[] = [{ kind: "circle", radius: 1 }, { kind: "rect", width: 2, height: 3 }];
for (const s of shapes) console.log(s.kind, area(s).toFixed(2));
enum Status {
Todo,
Doing,
Done,
}
const tasks: { title: string; status: Status }[] = [
{ title: "write", status: Status.Done },
{ title: "test", status: Status.Doing },
{ title: "ship", status: Status.Todo },
];
for (const task of tasks) {
console.log(task.title.padEnd(6), Status[task.status]);
}
An async retry helper
async function retry<T>(task: () => Promise<T>, times: number): Promise<T> {
for (let attempt = 1; ; attempt++) {
try {
return await task();
} catch (error) {
console.log(`attempt ${attempt} failed: ${(error as Error).message}`);
if (attempt === times) throw error;
}
}
}
let calls = 0;
const flaky = async () => {
calls++;
if (calls < 3) throw new Error("not yet");
return "ok";
};
console.log(await retry(flaky, 5));
Reading input in TypeScript
Programs here do not stop and wait for you to type while they run. Everything your program reads comes from the input box, which you fill in before pressing Run.
Use prompt() to read one line of the input box at a time. Its type is string | null: convert numbers with Number() and handle null, which means the input has run out.
Saving and sharing
Your latest TypeScript code and input are saved automatically in this browser, so they are still here when you come back. Nothing is saved on a server.
Share creates a link that carries your code inside the address itself, compressed after the # sign. Whoever opens it sees your code in the editor, and it only runs when they press Run.
Keyboard shortcuts
Keys
Action
Ctrl+Enter
Run the code
Ctrl+/
Comment or uncomment the line
Tab · Shift+Tab
Indent or outdent the selection
Ctrl+F
Find and replace in the code
Ctrl+Z · Ctrl+Shift+Z
Undo / redo
Esc → Tab
Leave the editor with the keyboard
On a Mac, use ⌘ instead of Ctrl.
Frequently asked questions
Does this TypeScript compiler check my types?
No. It strips the types and runs the code, which keeps every run fast and needs no compiler download. Errors you see come from running the program. For type errors, run tsc locally or use an editor with TypeScript support.
Which TypeScript syntax can I use?
The everyday syntax works: interfaces, type aliases, union and intersection types, generics, enums, as and satisfies, non-null assertions, access modifiers, readonly, parameter properties and abstract classes. Code that relies on a tsconfig setting or on emitting declaration files has no effect here.
Can I import npm packages?
No. There is no package installer and no module bundler, so import statements for packages will fail. Write the code you need in the editor, or paste in small helper functions.
Is this TypeScript compiler free?
Yes. There is no account, no sign-up and no daily limit. The only limit is that a single run stops after 10 seconds.
Is my TypeScript code sent to a server?
No. The TypeScript runtime is downloaded into your browser and your code runs there, on your device. The site only serves the page and the runtime files; it never receives the code you write or the input you give it.
Where is my code saved?
In this browser's local storage, one draft per language. It stays until you clear this site's data, and it is not synced to other devices. Use a share link to move code somewhere else.
How do I share my TypeScript code?
Press Share and send the copied link. The code is compressed into the part of the link after #, which browsers never send to a server. Very long programs do not fit in a link, and the page will tell you when that happens.
Does it work on a phone or tablet?
Yes. It runs in any current mobile browser. On a slow connection the first run takes longer because the runtime has to be downloaded once.