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.

Lesson 2.24m 13sIntermediate17.5k students

Chapters

4:13
  1. 0:00Extending generic types
  2. 1:42Type Argument Inference
  3. 2:13Use different type arguments
  4. 3:29Generic type parameter defaults

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

Resources