Conditional types

A conditional type is produced as a result of evaluating a ternary expression.

  • todo: syntax

It is important to note in the example above that T does not refer to an actual string, but rather a type of string. Here's a more practical example using arrays and tuples.

Conditional type distribution

When a conditional extends is applied to a union type (e.g. T extends string | number), TypeScript distributes the condition over each member of the union.

Conditional type distribution only happens if T is a naked type parameter, which means it isn't wrapped in a tuple or other type construct.

Was this page helpful?