Annotated solution
Published July 22, 2026The solution
type Unwrap<T> = T extends Promise<infer Inner> ? Unwrap<Inner> : T
The common wrong answer
type Unwrap<T> = T extends Promise<infer Inner> ? Inner : T
This peels exactly one layer. `Promise<Promise<number>>` becomes `Promise<number>` and stops. The recursive call is what makes it total.
Line by line
T extends Promise<infer Inner>Pattern-matches `T` against the shape `Promise<something>` and binds that something to `Inner`.
? Unwrap<Inner>Recursion. `Inner` may itself be a promise, so the same question is asked again until the answer is no.
: TThe base case. Not a promise, so `T` is already the value type.
Takeaway
A conditional type that calls itself in its true branch is the type-level equivalent of a `while` loop. The false branch is the exit.