TypeScript Playground Guide
Try typed JavaScript, read transpilation errors and run coding exercises in a browser Worker.
Use the TypeScript Playground to try a typed snippet without setting up a project.
An interface disappears at runtime
Clear the editor, open Code examples, and choose Typed function. It adds:
interface Rectangle {
width: number;
height: number;
}
function area(rectangle: Rectangle): number {
return rectangle.width * rectangle.height;
}
console.log('Area:', area({ width: 6, height: 4 }));
Press Run. The first run downloads the compiler; later requests can use the browser’s normal HTTP cache. The output is Area: 24. The interface and annotations are removed before JavaScript executes: they describe types, not runtime validation.
For example, assigning a string to a variable annotated number is a semantic type error, but this runner may still execute it. Use a real TypeScript type checker when validating a project. The optional Monaco editor can show diagnostics, but those do not block Run.
Coding exercises and patterns
The examples include odd/even numbers, prime numbers up to 30, factorial, Fibonacci, FizzBuzz, palindrome, bubble sort, binary search, word frequency, OOP and six triangle/pyramid/diamond patterns. The shared JavaScript examples also work as TypeScript; Typed function and Generic function demonstrate TypeScript-specific syntax.
Choosing an example preserves your current code below it, pauses Auto-run, and shows an explanation of the expected result. Clear first if you want a single exercise. Star-pattern spaces are significant; the output uses monospace text and Copy output preserves those spaces and line breaks.
Input, limits and privacy
Use await prompt('Your name?', 'Ilham') for input and Send input to resume execution. This prompt returns a Promise, unlike window.prompt.
Each Run starts a fresh Worker. Stop interrupts even an infinite loop. Execution is limited to 30 seconds and 500 output rows. Timers can continue logging after the snippet returns until Stop, the next Run or the execution limit.
The tool does not save or upload your code or input. Compiler and optional editor assets are fetched from jsDelivr, which receives ordinary asset requests. Snippets can make network requests through browser APIs, so only run code you trust. A Worker is not a security sandbox.
Related playgrounds
Reference
Questions you might have
- Does this check TypeScript types?
- No. The runner uses transpileModule, which removes types and reports syntactic errors. A mismatched type can still run. Monaco may display additional editor diagnostics when enabled, but the runner does not enforce them.
- Can I use await and interactive input?
- Yes. The transpiled snippet runs inside an async function. Use await prompt(‘Question’) and enter an answer in the output panel. Ask one question at a time; return displays a result.
- Does clicking an example run it?
- No. An example is inserted in a separate block above existing code, and Auto-run is paused. Clear the editor first to run only that example, then press Run.
- Can I import npm packages?
- No. This is a single-snippet browser runner, not Node.js or a project bundler. document and window are also unavailable inside the Worker.
- What happens when code never finishes?
- Stop terminates the Worker. Runtime loading has a 90-second timeout, and execution has a separate 30-second limit. Output is capped at 500 rows; input remains available to edit.