Online TypeScript Compiler
Write, run and test TypeScript code online, right in your browser. This free online TypeScript compiler needs no installation or signup — just type your code and click Run.
TypeScript adds static types to JavaScript, catching mistakes before your code runs. It is the standard choice for large front-end and Node.js projects.
How to use the TypeScript compiler
- Write or paste your TypeScript code in the editor.
- If your program reads input, open the I/O tab and type it into the STDIN box (one value per line).
- Click Run — the output and any errors appear in the output panel.
Sample: read input in TypeScript
const input: string = require('fs').readFileSync(0, 'utf8').trim();
const greet = (name: string): string => `Hello, ${name}!`;
console.log(greet(input));
Paste this into the editor, type your name in the STDIN box and click Run.
More TypeScript examples to try
Interfaces and typed functions
An interface describes the shape of an object, and the compiler checks every use of it.
interface User {
name: string;
age: number;
email?: string; // optional
}
function describe(u: User): string {
return `${u.name} (${u.age})${u.email ? " - " + u.email : ""}`;
}
const users: User[] = [
{ name: "Asha", age: 24, email: "asha@example.com" },
{ name: "Ravi", age: 31 },
];
users.forEach(u => console.log(describe(u)));
Generics
A generic function works with any type while keeping full type safety.
function firstOrDefault<T>(items: T[], fallback: T): T {
return items.length > 0 ? items[0] : fallback;
}
console.log(firstOrDefault([10, 20, 30], 0));
console.log(firstOrDefault<string>([], "empty"));
Common TypeScript errors and how to fix them
error TS2322: Type 'string' is not assignable to type 'number'- You assigned a value of the wrong type. Convert it first, e.g.
Number(text), or fix the declared type. error TS2339: Property 'x' does not exist on type- The object type does not declare that property. Add it to the interface, or check the spelling.
error TS7006: Parameter 'x' implicitly has an 'any' type- Strict mode requires types on parameters. Add one, e.g.
(x: number) => .... error TS2532: Object is possibly 'undefined'- The value may be missing. Check it first with
if (obj), or use optional chainingobj?.prop.
Frequently asked questions
Is this online TypeScript compiler free?
Yes. It is completely free to use, with no signup required to write and run code.
Do I need to install anything?
No. It all works from your web browser, so there is nothing to download or set up — it works on Windows, macOS, Linux, Chromebooks and phones.
How do I give input to my TypeScript program?
Before clicking Run, type the input into the STDIN box under the I/O tab, one value per line. Your program reads it as standard input, just like typing in a terminal.
Is this good for learning TypeScript?
Yes. It is ideal for practising exercises, testing small programs and trying out ideas from tutorials, because you can run code instantly without configuring an environment.
Other online compilers
Python Compiler Java Compiler C Compiler C++ Compiler C# Compiler JavaScript Compiler SQL Compiler React.js Compiler HTML Compiler Go Compiler Rust Compiler R Compiler PHP Compiler Kotlin Compiler Swift Compiler Scala Compiler Dart Compiler Ruby Compiler Prolog Compiler Perl Compiler
Editor powered by OneCompiler.