Welcome to XCODX Online Compiler
Quick Start:
Ctrl+Enter Run code
Ctrl+S Save / Download
Ctrl+L Clear output
Select a language and start coding.
Welcome to XCODX Online Compiler
Quick Start:
Ctrl+Enter Run code
Ctrl+S Save / Download
Ctrl+L Clear output
Select a language and start coding.
TypeScript is a statically typed superset of JavaScript created by a Microsoft team led by Anders Hejlsberg and first released in 2012. Every valid JavaScript program is also valid TypeScript; the language adds a type layer on top, annotations, interfaces, generics, enums, and union types, that the compiler checks and then erases, emitting plain JavaScript. Because the types exist only at compile time, they catch mismatches before the program runs but add nothing to the running code. It is the language Angular is written in, is widely adopted across React and Vue projects, and increasingly backs Node.js services and libraries where a typed public API helps callers. This page compiles your TypeScript with the TypeScript compiler and runs the resulting JavaScript on server-side Node.js, with the version shown in the badge.
interface Point {
x: number;
y: number;
}
function distance(a: Point, b: Point): number {
return Math.hypot(a.x - b.x, a.y - b.y);
}
const points: Point[] = [{ x: 0, y: 0 }, { x: 3, y: 4 }];
console.log(`distance = ${distance(points[0], points[1])}`);
const doubled = points.map((p): Point => ({ x: p.x * 2, y: p.y * 2 }));
console.log(doubled);
TypeScript earns its keep once a codebase is large enough, or has enough contributors, that catching type errors and getting accurate editor autocomplete before runtime outweighs the extra annotations and the compile step. It is the default for most modern front-end frameworks and a common choice for Node back ends and shared libraries whose consumers benefit from a typed interface. For a throwaway script or quick experiment, the build step and annotations are overhead you may not want, and since types are erased before execution, data arriving from input or JSON still has to be validated at runtime by hand.
Both: the TypeScript compiler checks your code and reports type errors, then the JavaScript it emits is executed on Node.js. The runtime version is shown in the badge next to the language name. This is server-side execution, so console.log is how you print output.
TypeScript is JavaScript plus an optional static type system, so any JavaScript you paste already compiles. The types, interfaces, generics, and enums are checked at compile time and then removed, leaving ordinary JavaScript to run, which means the two behave identically at runtime. The gain is catching type mistakes and getting better tooling before the program executes.
No. There is no npm install, so third-party packages and their @types definitions cannot be downloaded. You can use Node's built-in modules (fs, readline, path, crypto) and TypeScript's bundled lib types for things like Array, Promise, and Map, but importing lodash, axios, or express, or their @types, fails with "Cannot find module".
Read it the Node.js way, through process.stdin, usually via the built-in readline module: const rl = require('readline').createInterface({ input: process.stdin }); rl.on('line', (line: string) => { console.log(line); });. There is no prompt() because this is not a browser. Type into the live terminal when a prompt pauses, or paste all input into the Stdin Box, and end the stream with Ctrl+D.
No. The code runs under Node.js, not a browser, so there is no document, window, or DOM. A global fetch may exist, but the sandbox has no network access, so requests cannot reach any server. The filesystem is also fresh each run and discarded afterward, so nothing persists.
No. Types are a compile-time feature and are erased before the code runs, so at runtime a value that does not match its declared type is not re-checked by TypeScript. That is why external data, such as parsed JSON or user input, can still hold a shape your types claim it does not, and you should validate it yourself before trusting it.
main.tsjavascriptprocess.stdinconst message: string = "Hello from TypeScript!";
console.log(message);
const greet = (name: string): void => {
console.log(`Welcome, ${name}!`);
};
greet("XCODX User");