Lesson 1.1

Structural typing and assignability

TypeScript compares shapes, not names. Two unrelated types are interchangeable if their members line up, which explains most surprising assignability errors.

Duration
12m
Level
Intermediate
Students
22k students

Overview

TypeScript compares shapes, not names. Two unrelated types are interchangeable if their members line up, which explains most surprising assignability errors.

In this lesson you will:

  • Compare types by structure rather than declaration
  • Read an assignability error from the mismatched member up
  • Use branded types when structural compatibility is too loose

Resources

TypeScript handbook

The official reference for the tools used in this lesson.