Course page
Log in

You are watching a free preview. Enroll to open all 25 lessons, track progress and ask the course tutor.

Enroll for $49.99

Section 1: Thinking in types

What TypeScript is and is not

Video 8 min Lesson 1 of 25 Sample clip Preview

TypeScript is JavaScript with static types. You write .ts files that look like JavaScript plus type annotations, and a type checker analyses them before the code runs. If it finds a mismatch, such as calling a function with a string where it expects a number, it reports an error in your editor.

function total(prices: number[]): number {
  return prices.reduce((sum, p) => sum + p, 0);
}

total([10, 20]);     // fine
total(["10", "20"]); // error: string is not assignable to number

Types disappear at runtime

This is the most important idea in the course. TypeScript types exist only during development. When the code is compiled or run, the types are removed and what remains is ordinary JavaScript. Nothing checks types while the program is running.

That has two consequences:

  1. TypeScript cannot protect you from bad data coming from outside: an API response, a form, a file. You still need runtime validation at those boundaries.
  2. Types add no runtime cost. They do not make code slower or larger.

Ways to run TypeScript

  • The tsc compiler checks types and outputs JavaScript.
  • Bundlers and frameworks such as Vite or Next.js strip types quickly and leave checking to your editor and a separate tsc --noEmit step.
  • Recent versions of Node.js can run many .ts files directly by stripping type annotations, and runtimes such as Deno and Bun support TypeScript natively.

In all cases the type checking itself is done by the TypeScript compiler, usually in your editor and in CI.

Why it is worth it

  • Editors can autocomplete properties and show documentation everywhere.
  • Renaming a property updates every usage safely.
  • Many bugs, such as typos in property names or forgotten null checks, are caught before running the code.
  • Types document how functions should be used, and that documentation cannot go out of date.

What it does not do

TypeScript does not make your logic correct. A function can be perfectly typed and still calculate the wrong total. You still need tests. Think of types as a fast, always on check for a specific category of mistakes.

Open the TypeScript playground in your browser. We use it for the first exercises.

← → switch lessons