1×
Become a member
to unlock all features
Autoplay

    Use TypeScript conditional types to create a reusable Flatten type

    typescriptTypeScript
    ^3.0.0

    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.