What is TypeScript and where it runs

What TypeScript is

TypeScript is a language built on top of JavaScript that adds static types. You write familiar JavaScript code plus short notes about which values are numbers, strings, arrays, and objects. A compiler then checks those notes before the program ever runs.

function add(a: number, b: number): number { return a + b; } console.log(add(2, 3));

5

The add function above accepts two numbers and returns a number. When the call matches those notes, the compiler stays silent and the program prints 5.

Where it runs

TypeScript never runs directly. The tsc compiler erases the type notes and emits plain JavaScript, and that output runs in every place JavaScript runs: browsers, servers driven by Node, and desktop or mobile runtimes built on JavaScript engines.

function add(a, b) { return a + b; }

The compiled output keeps the logic and drops the annotations. Types exist only at compile time, so they add safety without slowing the running program.

Why types pay off

Types turn silent wrong behavior into loud early errors. The next line does not compile, and that is exactly the point. The compiler stops a mistake that plain JavaScript would accept and run with:

const age: number = "thirty";

error TS2322: Type 'string' is not assignable to type 'number'.

Large projects gain the most. Type notes document what each function expects, editors suggest correct members while you type, and refactors become safer because the compiler lists every spot that still uses the old shape.

How it relates to JavaScript

Every valid JavaScript program is already a valid TypeScript program. You can rename a js file to ts, compile it at once, and add type notes step by step where they help the most.

Plain JavaScript becomes typed TypeScript by adding two short notes:

function greet(name) { return "Hello, " + name; } function greetTyped(name: string): string { return "Hello, " + name; }

Next: Install TypeScript

Article author: Arthur Isaev