Skip to content

Foundations & Mental Model

TypeScript is JavaScript plus a static type system that runs at compile time and disappears at runtime. It doesn’t change what your code does — it changes what the compiler will let you write, catching whole classes of bugs before the code ever runs.

Everything advanced in this course — generics, conditional types, mapped types — is just this one system taken to its logical conclusion. Get the mental model right and the rest follows.

LessonWhat you’ll learn
Why TypeScriptWhat types buy you, and the compile-time / runtime split
The type-system mindsetTypes as sets of values — the single most useful mental model
Structural typingWhy TypeScript cares about shape, not names
Type inferenceHow the compiler figures out types you didn’t write

Two ideas, held together, explain almost every TypeScript behavior you’ll ever hit:

flowchart TB
  sets["Types are SETS of values
(number = all numbers)"] --> assign["Assignability =
subset relationship"]
  struct["Typing is STRUCTURAL
(shape, not name)"] --> compat["Compatibility =
does the shape fit?"]
  assign --> ts["Every TS behavior"]
  compat --> ts
The two ideas everything builds on

When an assignment is allowed, it’s because one type’s set of values fits inside another’s. When two objects are interchangeable, it’s because their shapes match. Hold those two ideas and TypeScript stops surprising you.

When does TypeScript's type system do its work?
What is the most useful mental model for a TypeScript type?
Which two ideas explain most TypeScript behavior?