TypeScript
main.tsSaved

Code

15 px

Ctrl + Enter Run · Ctrl + Shift + Enter Visualize · Ctrl + / Comment

Each prompt() call reads the next line.

Ready

Output

Press Run to see the output here.
Saved on this deviceRuns in your browser · no networkLn 1, Col 1Spaces: 2TypeScript

Online TypeScript compiler

Type-check and run TypeScript in your browser with the real TypeScript compiler. Type errors are shown the way tsc prints them, and the visualizer can replay any run step by step.

About the TypeScript compiler

How to use the TypeScript compiler

Write a program in the editor or pick a template: input with types, interfaces, generics, union types, a class, enums and tuples, type guards, a word count with a Map, async/await and utility types. Press Run or Ctrl+Enter. The program is checked first: if it has type errors, they are listed and nothing runs. Otherwise its output appears below, with console.error and console.warn in red.

How type checking works

StepVioz runs TypeScript 5.9, the same compiler as tsc, in strict mode with the ES2022 standard library. An error is printed the way tsc prints it, for example main.ts(3,7): error TS2322: Type 'string' is not assignable to type 'number'. The two numbers are the line and the column, and the TS code is worth searching for. The card under the output explains the most common errors in plain words.

How input works

Each prompt() returns the next line of the Input tab. Its type is string | null, because there may be no line left, so write prompt() ?? "" for text, or Number(prompt()) for a number.

What runs your code

After the check, the types are removed and your program runs as JavaScript in your browser's own engine, inside a sandbox with no access to the page, the network or your files. setTimeout, promises and async functions work on a virtual clock, and Math.random gives the same numbers every run, so tests stay repeatable. The compiler is a 1.6 MB download the first time; after that, a check takes a moment.

Each run may take 10 seconds; then it is stopped. Output is kept up to 10,000 lines or 1 MB, and the rest is cut with a notice. Programs cannot reach the network, and no packages or libraries can be installed: what a language brings with it is what you can use. A loop that never ends is stopped at 10 seconds, keeping what it printed.

See it step by step

Visualize this run opens the program and its input in the TypeScript visualizer, which shows the call stack, variables, and objects, arrays, Maps and class instances on the heap, on the lines of TypeScript you wrote. It follows the first 1,000 steps.

Questions

Is this online TypeScript compiler free?
Yes. There is no sign-up and no limit on how many programs you run.
Is it the real TypeScript compiler?
Yes. It is Microsoft's TypeScript compiler, version 5.9, running in your browser in strict mode, so its errors are the ones tsc gives.
Does my code go to a server?
No. It is checked and run inside your browser, in a sandbox with no network access. Nothing you write is uploaded.
Why is prompt() a string | null?
Because there may be no input left, and then prompt() returns null. Strict mode makes you handle that: prompt() ?? "" gives an empty string instead.
Can I import packages from npm?
No. There is no network and no node_modules. The ES2022 standard library is all there: Map, Set, Promise, and the methods of arrays, strings and numbers.

See also