BuildBot

Types in Motion

Generics & constraints

Lesson 2 of 3

Write one function that stays type-safe across many types — and constrain it when you need a guarantee.

What you'll learn

  • Write a generic function that preserves its input type
  • Add a constraint with extends to require certain shape
  • See why generics beat any for reusable code
Members only

A free account unlocks this lesson and every other one.

Runnable challenges, knowledge checks, and progress that syncs across your devices. No card needed.

Not sure yet? Try the free lesson first: Narrowing & discriminated unions