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] : never
This 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 `never` produces `never` and the base case would never be reached.
K extends KA conditional that is trivially true, used purely for its side effect: it distributes `K` so the branch below runs once per union member. `K` defaults to `T`, keeping an untouched copy while `T` is narrowed by `Exclude`.
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`.