TypeScript

34 lessons

Achievements
Combined Shape@2x

The Certificate

avatar

Distributive Conditional Types

When developers pair conditional types with a generic type, they become distributive when assigned a union type.

Let’s look at the following example:

When a union type is plugged into Array, a condition type will be assigned to all the members of the given union.

SArrOrNArr is distributed on string | number; and thus maps over each member of the union Array<string> | Array<number>;