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.

4mIntermediate17,541 students
Video thumbnail for Constraints and default type parameters

Sign in to watch this lesson

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

Overview

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

What this lesson covers

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

This lesson sits in Generics, 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:

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