Annotated solution
Published August 8, 2026The solution
type Permutation<T, K = T> = [T] extends [never] ? [] : K extends K ? [K, ...Permutation<Exclude<T, K>>] : never
The common wrong answer
type Permutation<T> = T extends T ? [T] : neverThis distributes and wraps each member in its own tuple, giving ["a"] | ["b"] — every member alone, never combined. It also answers never for never, because distributing over the empty union produces nothing rather than the empty tuple.
Line by line
[T] extends [never]The tuple wrapper suppresses distribution, which is essential here: a distributive conditional over
neverproducesneverand the base case would never be reached.K extends KA conditional that is trivially true, used purely for its side effect: it distributes
Kso the branch below runs once per union member.Kdefaults toT, keeping an untouched copy whileTis narrowed byExclude.
Takeaway
K extends K is the idiom for "distribute this union" and [T] extends [never] is the idiom for "do not". Knowing both, and which one a line needs, is most of what separates working type-level code from code that silently returns never.

