Skip to content

TypeScript

In one line

TypeScript is a strongly typed programming language that builds on JavaScript by adding static type definitions, catching errors before the code runs.

In simple words

TypeScript is JavaScript with types. It adds a static type system on top of JavaScript, letting you declare the types of variables, function parameters, and return values. The TypeScript compiler (tsc) checks that your code uses types correctly, then erases all type annotations and outputs plain JavaScript.

Think of it as a safety net: JavaScript lets you do anything at runtime, which can lead to bugs. TypeScript catches many of those bugs at compile time — before the code ever runs. For example, if you try to call a string method on a number, TypeScript tells you immediately.

TypeScript is a superset of JavaScript, meaning every valid JavaScript program is also a valid TypeScript program (with relaxed settings). This makes it easy to adopt incrementally — you can rename .js files to .ts and add types gradually.

Example

typescript
let count: number = 5;
let name: string = "Alice";

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

console.log(add(count, 10)); // 15

Type annotations (: number, : string) are checked at compile time, then erased. The output is plain JavaScript.

Related terms

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to glossary