Use TypeScript conditional types to create a reusable Flatten type

InstructorRares Matei

Share this video with your friends

Send Tweet

Generics can be a useful mechanism for transforming one type into another. In this lesson we will look at how we can use them to create different types for flattening array and object types (extracting the types of their boxed values). We will then look at how we can use conditional types to create a single multi-purpose Flatten type, that can dynamically chose a flattening strategy based on the type passed into it.