TSTypeScript · Lesson 6 of 10
Generics
Generics let you write code that works with many types while staying type-safe. Think of `<T>` as a type parameter — like a function parameter, but for types.
✦ Tip
Start with `<T>` and add constraints (`T extends SomeType`) only when the compiler tells you a property doesn't exist. Over-constraining generics defeats the purpose. The goal is to capture the relationship between input and output types, not to enumerate every property.
Start with `<T>` and add constraints (`T extends SomeType`) only when the compiler tells you a property doesn't exist. Over-constraining generics defeats the purpose. The goal is to capture the relationship between input and output types, not to enumerate every property.