Day 8 of 14 30 minGeneric functionsConstraintsGeneric types
Write functions, types and classes that work with any type while staying fully type-safe. Use type parameters, let TypeScript infer them, add constraints with extends, and build reusable generic types like an API response wrapper.
By the end of today you can
- Explain what problem generics solve compared with any
- Write generic functions and let TypeScript infer the type arguments
- Constrain type parameters with extends and keyof
- Write generic interfaces and type aliases
- Recognise generics in built-in types like Array<T>, Promise<T> and Record<K, V>
What's inside
- 5 sections
- 2 diagrams and mind maps
- 6 code examples you can run
- 5-question quiz
- 1A first generic function
- 2Several type parameters
- 3Constraints: extends
- 4Generic types
- 5You've been using generics all along
Sign in free to read this lesson
Get the full lesson with diagrams, runnable code and the quiz. Your progress is saved across devices.
Sign in free