Introduction

Topic 1 of 3 in Getting started8 min readIntermediateFree course

Overview

TypeScript is JavaScript with types. You write the same code you’d write in JavaScript — functions, objects, classes, async/await — and add a few annotations that say what kind of values things hold. A program called the type checker reads those annotations and tells you about mistakes before the code ever runs.

It has become the default way to write serious JavaScript. Most new web frameworks, Node.js backends and npm packages are written in TypeScript, and job listings for front-end and full-stack roles increasingly expect it.

This course takes you from your first annotation to the advanced type features that libraries use, and finishes with a complete, fully typed, tested API.

Your path through TypeScript, in four stages. Foundations: 1 Getting started, 2 Everyday types, 3 Objects and functions. Precise types: 4 Unions and narrowing, 5 Modelling data, 6 Generics. Advanced: 7 Type operators, 8 Classes, 9 Modules and declarations. Production: 10 Async and runtime safety, 11 Config and tooling, 12 TypeScript in practice. Every lesson ends with an exercise checked by the TypeScript compiler, and the course finishes with a fully typed, tested Node.js API you build yourself.

The problem TypeScript solves

JavaScript is flexible. That’s great for small scripts and painful for big programs:

JavaScript
function orderTotal(prices, shipping) {
  let sum = shipping;
  for (const price of prices) sum += price;
  return sum;
}

orderTotal([7.25, "12.50"], 3);   // "10.2512.50" — not 22.75

No error, no warning: JavaScript turned the sum into text and carried on. You find out later — maybe from a customer. In a codebase with thousands of functions and several developers, mistakes like these, along with typos in property names and forgotten null checks, are the most common bugs there are.

Here’s the same function in TypeScript:

TypeScript
function orderTotal(prices: number[], shipping: number): number {
  let sum = shipping;
  for (const price of prices) sum += price;
  return sum;
}

orderTotal([7.25, "12.50"], 3);
//                ~~~~~~~
// error TS2322: Type 'string' is not assignable to type 'number'.

The annotations : number[] and : number say what the function expects. The mistake is underlined in your editor the moment you type it.

How it works: checked, then erased

Types are checked, then erased. TypeScript you write, such as a cart.ts file with a type Item and a function total(items: Item[]): number, goes two ways. The type checker (tsc or your editor) reports errors, before anything runs. Type erasure (tsc, Node, Vite and others) removes the annotations, producing cart.js — the same function without types — which is what runs. Browsers and Node only ever run JavaScript, so types cost nothing at run time — and also check nothing at run time.

Two separate things happen to TypeScript code:

  1. Type checking. The checker reads your whole project and reports anything that doesn’t add up. This happens in your editor as you type, and on the command line with tsc.
  2. Type erasure. The annotations are removed, leaving plain JavaScript. Browsers and Node.js only ever run JavaScript.

Two consequences follow, and they’re worth remembering from day one:

  • Types have zero cost at run time — the JavaScript is as fast as if you’d written it by hand.
  • Types do nothing at run time either. They can’t check data that arrives while the program runs, such as a JSON response from an API. You’ll learn how to deal with that in Validating external data.

What you get

  • Fewer bugs. Wrong arguments, misspelled properties, impossible nulls and forgotten cases are caught immediately.
  • A much better editor. Autocomplete knows every property of every object; you can rename a function across 200 files safely; hovering shows what anything is.
  • Code that documents itself. function send(to: Email, body: string): Promise<void> tells you more than a comment would — and it can’t go out of date.
  • Confident refactoring. Change a type, and the checker lists every place that needs updating.

The cost is some extra writing and a learning curve. TypeScript is designed to keep both small: it infers most types for you, and you can adopt it gradually, one file at a time.

TypeScript in 2026

  • TypeScript 7, released in July 2026, replaced the compiler with a native port written in Go. It checks the same code the same way, but typically 8–12× faster. This course uses TypeScript 7.
  • TypeScript 6 (March 2026) modernised the defaults: strict checking is on by default and legacy options are gone. If you read older tutorials, some settings they mention no longer exist.
  • Node.js (22.18 and later, including Node 26 LTS) can run .ts files directly by stripping the types, so small projects don’t need a build step at all.

What you need

  • Comfort with JavaScript basics: variables, functions, arrays, objects, and ideally async/await. (Our JavaScript Essentials course covers all of it.)
  • Node.js 22.18 or newer (Node 26 recommended) and a code editor — the next lesson walks through the setup.

How the course works

Each lesson explains one idea with examples, diagrams of what the type checker is doing, and an exercise. Every exercise solution in this course has been checked with the TypeScript compiler; many use // @ts-expect-error comments to show a line that TypeScript must reject — a technique you’ll use yourself.

Mindset: a type error isn’t the compiler being difficult. It’s a bug report delivered before the bug ships. Read it, and let it teach you.

Exercise

Let the types find the bug

The starter is plain JavaScript inside a .ts file. It has a bug that JavaScript happily runs: a price arrives as the string "12.50" and gets glued onto the other number instead of added to it. TypeScript already complains that the parameters implicitly have an any type. Annotate the three parameters of orderTotal (a list of numbers, a number and a string) and its return value (a string); TypeScript will then point straight at the bad data. Fix it so the program prints Total: 22.75 USD. Also keep a copy of the bad call inside a function that is never run, with // @ts-expect-error on the line above it, to prove TypeScript catches it.

TypeScript
function orderTotal(prices, shipping, currency) {
  let sum = shipping;
  for (const price of prices) {
    sum += price;
  }
  return `Total: ${sum.toFixed(2)} ${currency}`;
}

const prices = [7.25, "12.50"];   // one price came from a form, as text
console.log(orderTotal(prices, 3, "USD"));

Summary

  • TypeScript is JavaScript plus a type system: every JavaScript program is valid TypeScript syntax, and you add types where they help.
  • Types are checked before the code runs, then erased — the code that actually runs is ordinary JavaScript.
  • The checker catches typos, wrong arguments, missing properties and forgotten null checks while you type.
  • Types also power the editor: autocomplete, safe renames and inline documentation.
  • This course uses TypeScript 7 (the fast native compiler) and Node.js 26, which runs .ts files directly.