Course contentsShow
← TypeScript
Lesson 770 of 1,79618. Conditional TypesFree lesson

Non-Distributive Conditionals

Learn to prevent distribution by wrapping the checked type in a tuple: [T] extends [U] ? X : Y.

Non-Distributive Conditionals

What you'll learn: How to prevent conditional types from distributing over union members by wrapping the checked type in a tuple.

The Distribution Problem

By default, when you pass a union type to a conditional type, TypeScript automatically distributes the condition over each member of the union. This happens when the checked type (the thing before extends) is a naked type parameter—a bare T without any wrappers.

Sometimes you don't want this behavior. You want to check the entire union as a single entity, not each member separately.

The Tuple-Wrapper Solution

To prevent distribution, wrap the checked type in a tuple:

// Distributes (default behavior)
type Distributed<T> = T extends string ? "yes" : "no";
type Result1 = Distributed<string | number>;
// Result1 = "yes" | "no" (checked each member separately)

// Non-distributive (tuple wrapper)
type NonDistributed<T> = [T] extends [string] ? "yes" : "no";
type Result2 = NonDistributed<string | number>;
// Result2 = "no" (checked the whole union at once)

The tuple wrapper [T] makes the type parameter no longer "naked," so TypeScript checks whether the entire type (the union string | number) extends [string]. It doesn't, so the result is "no".

Why This Matters

Non-distributive conditionals let you:

  • Detect whether a type is exactly a union
  • Check properties of the complete type structure
  • Avoid unwanted distribution when working with complex type transformations

Key Takeaway: Wrap both sides of a conditional in tuples—[T] extends [U] ? X : Y—to prevent distribution and check the type as a whole instead of checking each union member separately.