Online TypeScript Compiler

Compile TypeScript with the official 5.9 compiler and run the result in your browser. Syntax errors are reported; types are erased, not checked.

Runs in your browser · Nothing uploadedFree · No sign-upTypeScript 5.9

Start from an example

main.ts

Standard input (stdin)

Output

Nothing has run yet

Press Run to see what the program prints, or load one of these:

Embed this compiler

Paste this into your page. Visitors run code in their own browser, and nothing is sent to us.

TypeScript, compiled by the real compiler

Your code goes through the official TypeScript 5.9 compiler in transpile-only mode. The JavaScript it produces runs in your browser's engine, inside a sandboxed Web Worker.

Know this before you start: types are erased, not checked. A syntax error stops the run, but const n: number = 'text' runs without complaint. For type errors, run tsc --noEmit on your machine.

At a glance
Compiler
TypeScript 5.9.3
Mode
Transpile only
Output
ES2022, CommonJS
Input
prompt(), readline, fs.readFileSync(0)
Run limit
10 seconds
First load
About 9 MB, then cached

What works and what does not

We ran every row of this table in the compiler before writing it down.

FeatureWorks?
Interfaces, generics, unions, enums

Removed or turned into plain objects, the same as tsc does.

Yes
satisfies, optional chaining, ??=

Anything the 5.9 parser understands.

Yes
Decorators (TC39 standard)

Method and class decorators run as written.

Yes
import and export

Compiled to CommonJS, so import * as readline from 'readline' and import fs from 'fs' both work.

Yes
Syntax errors

Shown as main.ts(line,column): error TS…, and the run stops.

Yes
Type checking

Type errors are not reported. The code runs anyway.

No
Line numbers in runtime errors

You get the message without a line, because the line would point at the compiled JavaScript.

No
npm packages, DOM, network

Same limits as the JavaScript compiler.

No

Why run TypeScript here

The real compiler, not a type stripper

Enums, namespaces and parameter properties need generated code, and they get it, because this is TypeScript’s own compiler.

import syntax works

Unlike the JavaScript compiler, you can write import fs from 'fs'. It becomes a require() call before the code runs.

Same input helpers as JavaScript

prompt(), readline and fs.readFileSync(0) read the stdin box, so the same input code works on both pages.

One download

The compiler is about 9 MB (under 2 MB compressed). Your browser caches it, so the next visit skips the download.

Errors you will probably hit

Two of these are about what the compiler does not do.

main.ts(1,19): error TS1109: Expression expected.

What it meansA syntax error. The numbers are the line and the column.

FixGo to that spot. The problem is usually a missing value, bracket or comma just before it.

No error for const n: number = 'text'

What it meansTypes are erased, not checked.

FixRun tsc --noEmit locally when you need type errors.

Error: Cannot find module 'express'

What it meansnpm packages are not available. An import you never use is dropped by the compiler, so this only appears once the import is used.

FixRemove the dependency, or write the part you need by hand.

TypeError: Cannot read properties of null (reading 'x')

What it meansA value was null at run time, whatever its type said.

FixGuard it with optional chaining (o?.x) or an if check. Runtime errors have no line number here, so a console.log helps you find the spot.

How this Online TypeScript Compiler works

When you press Run, the page passes your code and stdin to a sandboxed frame that cannot see this site, your cookies or the network. Inside it, a Web Worker loads the TypeScript compiler, turns your code into JavaScript and runs the result.

The compiler downloads on the first run and your browser caches it. If the code has a syntax error, you see the compiler's message and the run stops there. Type errors are not checked.

How to use this Online TypeScript Compiler

1

Write your code

Start from the sample, pick an example above the editor, or paste your own.

2

Add stdin

One value per line. prompt() and readline() each take one line per call.

3

Run it

Press Run TypeScript or Ctrl+Enter. The first run downloads the compiler, then the output appears on the right.

Example Usage

A generic helper that groups numbers by the key a function returns.

Input
function groupBy<T, K extends string>(items: T[], key: (item: T) => K): Record<K, T[]> { const out = {} as Record<K, T[]>; for (const item of items) (out[key(item)] ??= []).push(item); return out; } console.log(groupBy([1, 2, 3, 4, 5], (n) => (n % 2 ? 'odd' : 'even')));
Output
{ odd: [ 1, 3, 5 ], even: [ 2, 4 ] }

Frequently Asked Questions

Does this check my types?
No. It compiles with transpileModule, which removes types without checking them. Syntax errors are reported, type errors are not. Run tsc --noEmit locally for those.
Which TypeScript version and settings are used?
TypeScript 5.9.3, target ES2022, module CommonJS, with esModuleInterop on. That last setting is why import fs from 'fs' works.
Can I use import and export?
Yes. They compile to require() and exports. Only readline, fs (for stdin) and util can be imported.
How do I read input?
The same way as in the JavaScript compiler: prompt() per line, require('readline') events, or fs.readFileSync(0, 'utf8') for everything at once.
Is my TypeScript code sent to a server?
No. It runs in your browser, inside a sandboxed frame and a Web Worker that cannot reach the network. Share links store the code after the # in the URL, and browsers never send that part to a server.
Why is the first run slower than in the JavaScript compiler?
Your browser has to download the TypeScript compiler first, about 9 MB (under 2 MB compressed). Later runs, and later visits, use the cached copy.

Related Tools

Comments

Comments are provided by Disqus, which sets cookies and processes data under its own privacy policy.

The Online TypeScript Compiler is maintained by CodeItBro. We aim to provide the best free developer tools on the web. If you have feedback or suggestions, please visit our contact page.

As featured on

CodeItBro - Free dev tools + practical guides to help you ship faster | Product HuntCodeItBro - Free Online Developer Tools badgeCodeItBro badgeFeatured on neeed.directory