Annotated solution
Published September 30, 2026The 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 : neverIt 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
[Whole] extends [T]Inside a distributed branch
Tis one member whileWholestill 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.

