Annotated solution
Published July 30, 2026The solution
type MyReturnType<T> = T extends (...args: never[]) => infer R ? R : neverThe common wrong answer
type MyReturnType<T> = T extends () => infer R ? R : neverA zero-parameter pattern only matches zero-parameter functions, so (a: number) => boolean falls through to never. The pattern must be permissive about parameters to be permissive about signatures.
Line by line
(...args: never[]) => infer RBecause parameters are contravariant, a parameter list of
never[]is assignable *from* every other parameter list. It is the safe way to write "a function of any shape" without reaching forany.infer Rinferin return position asks the compiler to solve for whatever sits there. It is the same mechanism as inferring an element type from an array — only the position changes.
Takeaway
infer can be placed anywhere a type can appear inside a pattern. Most of the standard library’s extraction helpers are one conditional with one infer in the right spot.

