Functions
ReturnType
The type a function gives back.
What it is
A conditional type with `infer` in the return position — the canonical example of pattern-matching a type. `infer R` declares a variable that the compiler fills in by matching, and the true branch is where you get to use it.
Examples
ReturnType<typeof makeUser>→{ id: number; name: string; }ReturnType<() => void>→voidReturnType<() => string | number>
→string | numberA union return type comes back whole; nothing distributes here.
Each resolved type above was printed by TypeScript 5.9.3, not written by hand.
What it does not do
- It does not take a function *value*. It takes a function *type*, which is why `ReturnType<typeof fn>` is the shape you always end up writing.
- It does not resolve overloads the way a call would. Given an overloaded function it reports the last signature, not the one your arguments would have picked.
Takeaway
`typeof` crosses from the value world to the type world; `ReturnType` then works inside it. Almost every use of one involves the other.