TypeScript
const greeting: string = "Welcome to Online IDE!";
console.log(greeting);
console.log("Start coding in TypeScript...");

Press Run or Ctrl ↵ to execute main.ts.
Type program input here while it runs.

TypeScript

Online TypeScript Compiler

Your code is compiled by tsc from TypeScript 7.0, and the JavaScript it emits runs on Node.js 24. Strict type checking is on by default, and a type error stops the run before any of your code executes. Programs that read input with readline wait for you to type in the terminal while they run.

Try it above

How TypeScript runs here

Versions
TypeScript 7.0 on Node.js 24
Build
tsc --types node main.ts
Run
node main.js
Limits per run
512 MB memory, 15 s of CPU time on half a core, 2 MB of output
Time
Up to 10 minutes a run (30 on a paid plan); waits 2 minutes for input (5 on a paid plan)
Sandbox
Each run gets its own Linux sandbox with no network access. Text files your program writes next to your code open as new tabs.
Good to know
Node.js types are included.

A typed program that reads input

This main.ts asks for a shopping list, keeps it in typed objects and prints the total. It uses node:readline/promises with top-level await, which works because a file with imports compiles to an ES module.

TypeScript
import * as readline from "node:readline/promises";
import { stdin, stdout } from "node:process";

type Item = { name: string; price: number; qty: number };

const rl = readline.createInterface({ input: stdin, output: stdout });

const count = Number(await rl.question("How many items? "));
const cart: Item[] = [];
for (let i = 1; i <= count; i++) {
  const answer = await rl.question(`Item ${i} (name price qty): `);
  const [name, price, qty] = answer.trim().split(/\s+/);
  cart.push({ name, price: Number(price), qty: Number(qty) });
}
rl.close();

const total = cart.reduce((sum, item) => sum + item.price * item.qty, 0);
const priciest = cart.toSorted((a, b) => b.price - a.price)[0];

console.log(`Total: ${total.toFixed(2)}`);
if (priciest) console.log(`Most expensive: ${priciest.name} at ${priciest.price.toFixed(2)}`);

Three items typed in; tsc prints nothing when the types check:

Terminal
$ tsc --types node main.ts
$ node main.js
How many items? 3
Item 1 (name price qty): pen 1.50 4
Item 2 (name price qty): notebook 3.25 2
Item 3 (name price qty): backpack 24.99 1
Total: 37.49
Most expensive: backpack at 24.99

Reading input in TypeScript

Input comes from Node.js, so you read it with readline. For questions and answers, await rl.question() from node:readline/promises, as above. For many lines, loop over the interface and stop on a count or a sentinel such as an empty line:

TypeScript
import * as readline from "node:readline";

const rl = readline.createInterface({ input: process.stdin });
let sum = 0;
for await (const line of rl) {
  if (line.trim() === "") break; // an empty line ends the input
  sum += Number(line);
}
rl.close();
console.log(`Sum: ${sum}`);
  • The terminal sends each line when you press Enter, but never an end-of-input signal (there’s no Ctrl+D). So fs.readFileSync(0) and code that waits for stdin’s end event sit until the input wait runs out and the run ends with “Session Killed due to Idle Timeout.” Read line by line instead.
  • Call rl.close() when you’ve read everything. An open interface keeps the program alive, waiting for input you’ll never type.
  • Number("") is 0 and Number("3 4") is NaN, and neither throws. Split the line first, then check the numbers with Number.isNaN().

Imports and more than one file

Run starts the open tab, or the Entry file you set in Run settings. tsc compiles that file and every file it imports, so add util.ts with the + next to the tabs and import it from main.ts:

TypeScript
// util.ts
export function median(xs: number[]): number {
  const s = xs.toSorted((a, b) => a - b);
  const mid = Math.floor(s.length / 2);
  return s.length % 2 ? s[mid] : (s[mid - 1] + s[mid]) / 2;
}

// main.ts
import { median } from "./util.js";

console.log(median([7, 1, 4, 10])); // 5.5

Write the import with .js, the name of the compiled file. tsc maps it back to util.ts while checking, and Node.js needs the real file name when it runs the ES module. Without the .js, tsc compiles without complaint and Node.js stops with ERR_MODULE_NOT_FOUND.

Use import rather than require(). In a file with imports, require is not defined at run time, even though the Node.js types let it compile.

Don’t add a tsconfig.json. tsc is given the file by name, and a tsconfig.json beside it makes the compile fail with “error TS5112: tsconfig.json is present but will not be loaded if files are specified on commandline.”

What isn’t available here

  • npm packages. There’s no node_modules, so import express, lodash or zod fails with TS2307. Node.js built-ins work: node:fs, node:path, node:readline, node:crypto, node:events, node:util and the rest.
  • Browser APIs. document and window type-check, because tsc’s default library includes the DOM types, but there’s no page at run time and the program stops with a ReferenceError.
  • The network. fetch() exists in Node.js 24, but runs are offline, so every request fails.
  • Compiler options. With no tsconfig.json you get tsc’s defaults, so you can’t switch strict off or turn on settings such as noUncheckedIndexedAccess or experimentalDecorators.

Errors you’ll see

  • “error TS2322: Type 'string' is not assignable to type 'number'.” A value doesn’t match the declared type. Text from input is always a string: convert it with Number() first.
  • “error TS7006: Parameter 'x' implicitly has an 'any' type.” Strict mode wants a type on every parameter it can’t infer. Write x: number.
  • “error TS18048: 'first' is possibly 'undefined'.” find(), Map.get() and optional fields can return undefined. Check with if, or give a default with ??.
  • “error TS2307: Cannot find module 'lodash' or its corresponding type declarations.” npm packages aren’t installed. Use a Node.js built-in or write the helper yourself.
  • “Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/tmp/out/util' imported from /tmp/out/main.js” An import without the .js extension. Write "./util.js".
  • “ReferenceError: document is not defined” Browser code running on Node.js. Print with console.log instead of changing the page.

For long errors about union or generic types, Fix with AI under the failed run explains the mismatch and proposes a change as a diff.

TypeScript 7.0 and Node.js 24 in practice

  • TypeScript 7.0 is the compiler ported to Go. The language and its error codes are the ones you know from 5.x, so answers you find for TS2322 or TS2339 still apply.
  • Strict mode is on, but noUncheckedIndexedAccess isn’t: with const xs = [1, 2, 3], the expression xs[10] is typed number and is undefined at run time.
  • The library target is recent, so toSorted(), Object.groupBy() and structuredClone() type-check and run on Node.js 24 without polyfills.
  • Top-level await needs the file to be a module. In a file with no import or export, tsc reports TS1375; add export {} or an import.
  • // @ts-expect-error on the line above silences one error and fails the build if that line ever stops being an error, which makes it safer than // @ts-ignore.

Questions

Which TypeScript version does this use?

TypeScript 7.0, compiled with tsc and run on Node.js 24. The Node.js type definitions are loaded with --types node, so process, Buffer and the node: modules are typed.

Is strict mode on?

Yes. tsc’s defaults apply, and strict is one of them, so implicit any and possibly-undefined values are errors. There’s no tsconfig.json to turn it off.

Can I use npm packages like lodash or axios?

No. Only Node.js built-ins are there, and runs have no network to install anything.

Why does my import compile but fail when it runs?

The output is an ES module, and Node.js resolves it by the exact file name. Import "./util.js" rather than "./util".

How do I read user input in TypeScript online?

Use node:readline: await rl.question("Name? ") from node:readline/promises, or for await (const line of rl) for many lines. Type your answers in the terminal while the program runs.

Can I use document or the DOM?

No. The compiled JavaScript runs on Node.js, not in a web page, so document and window are undefined at run time.