Getting Started

TypeScript Introduction

Learn what TypeScript is, how it extends JavaScript, and why developers love it.

What is TypeScript?

TypeScript is a strongly typed programming language that builds on JavaScript. It adds optional static types, which helps catch errors early — before your code runs.

TypeScript is compiled (or "transpiled") to plain JavaScript, so it runs everywhere JavaScript runs.

Why TypeScript?

  • Catch bugs early: Type errors are caught at compile time, not runtime
  • Better tooling: Your editor can offer smarter autocomplete, refactoring, and navigation
  • Self-documenting code: Types make your code easier to understand
  • Scales well: Especially valuable in large codebases and teams

TypeScript vs JavaScript

TypeScript is a superset of JavaScript — any valid JavaScript code is also valid TypeScript. You can adopt TypeScript gradually.

Example

typescript
// JavaScript (no types)
function add(a, b) {
  return a + b;
}
add(1, 2);      // 3
add("1", "2");  // "12" -- oops!

// TypeScript (with types)
function addTS(a: number, b: number): number {
  return a + b;
}
addTS(1, 2);      // 3
addTS("1", "2"); // Error! Argument of type 'string' is not assignable to parameter of type 'number'

// Type inference
let message = "Hello"; // TypeScript infers type as string
message = 42;          // Error! Type 'number' is not assignable to type 'string'

// Object types
type User = {
  id: number;
  name: string;
  email: string;
};

const user: User = {
  id: 1,
  name: "Alice",
  email: "alice@example.com",
};
Try it yourself — TYPESCRIPT