Lesson 2.2

Constraints and default type parameters

Constraints say what a type parameter must at least be. Combined with keyof, they give you property access that stays typed.

Duration
4m
Level
Intermediate
Students
18k students

Overview

Constraints say what a type parameter must at least be. Combined with keyof, they give you property access that stays typed.

In this lesson you will:

  • Constrain a parameter with extends
  • Use keyof to type property access generically
  • Give a type parameter a sensible default

Resources

TypeScript handbook

The official reference for the tools used in this lesson.