Lesson 1.1Free

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.

11mIntermediate22,110 students
Video thumbnail for Structural typing and assignability

Sign in to watch this lesson

Browsing is free. Create an account to play videos and track your progress.

Overview

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

What this lesson covers

  • 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

This lesson sits in How the Type System Thinks, part of TypeScript for Application Developers. It assumes what came before it and leads directly into the next lesson in the module.

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