Skip to content
webtype.orgwebtype.org

    ↑↓ move · ⏎ open · esc close

    No. 277 · September 29, 2026 · Moderate

    Is it a union?

    Implement IsUnion<T> so a union of multiple members is true, a single type is false, and never is also false.

    01

    Try the puzzle yourself

    Par 3

    Puzzle

    is-union.ts
    Stroke 1 of 3Not run yet

    Replace ??? — your solution is checked against the cases below. Tab indents; press Escape then Tab to move focus out.

    Checks

    3
    • IsUnion<string | number>—
      → true
    • IsUnion<string>—
      → false
    • IsUnion<never>—
      → false

    How a check is judged Exact type equality, not assignability — an intersection is not the same as the flattened object.

    How everyone did

    Fewer than 5 people have solved this one so far. The distribution appears once there is enough of a sample to mean anything.

    Short game

    Fewest characters

    No public scores yet.

    Archive
    02

    Annotated solution

    Published September 30, 2026

    The solution

    type IsUnion<T, Whole = T> =
      [T] extends [never]
        ? false
        : T extends Whole
          ? [Whole] extends [T] ? false : true
          : never

    The common wrong answer

    type IsUnion<T, Whole = T> = T extends Whole ? [Whole] extends [T] ? false : true : never

    It handles ordinary types and unions, but a naked conditional over never runs zero times and returns never. The explicit wrapped guard is the only branch that gets a chance to call it false.

    Line by line

    1. [Whole] extends [T]

      Inside a distributed branch T is one member while Whole still holds the original union. The wrapped comparison detects that difference without distributing again.

    Takeaway

    Union detection works by comparing one distributed member with a preserved whole; never needs its own guard because it produces no members.

    Uses