ReturnType<T>
Last updated: 2026-10-22
ReturnType<T> ReturnType
ReturnType<T> extracts the return type of a function type T. The idiom is ReturnType<typeof someFn>: whatever the function returns, the type follows automatically — no hand-copying the return shape, and refactors propagate.
| Group | Utility Types |
|---|---|
| Kind | Type |
| Strict mode | Not required |
ℹ️ Info The editor transpiles TypeScript to JavaScript and runs it (no type checking); see each example's Output for type-check results.
📝 Syntax
type ReturnType<T extends (...args: any) => any> =
T extends (...args: any) => infer R ? R : any;
// Usage
type Point = ReturnType<typeof makePoint>;
⚙️ Parameters
| T | A function type; in practice almost always obtained via typeof fn |
|---|
Returns:T's return type; if T is not a function type the result is any (guarded by the constraint, so little else gets through).
▶ Example
Edit the code below and click Try it to see the transpiled result:
Output:
5
0 0
(Runtime output after transpilation; at the type level Point automatically becomes { x: number; y: number; distance(): number } — change makePoint's return shape and Point follows)
💡 Notes
ℹ️ Info The implementation leans on infer: T extends (...args: any) => infer R ? R : any — infer "captures" the return type R inside the conditional. infer powers all extraction utility types.
⚠️ Note For overloaded functions, ReturnType uses the last overload signature's return type; earlier overloads are unreachable. With complex overloads, export the return type explicitly.
💡 Tip An async function's ReturnType is Promise<X>; to get X wrap it: Awaited<ReturnType<typeof fn>>. The most common combo in async code.
🏷️ Related Utility Types
💡 Related cases
More cases coming soon.
📚 Related tutorials
❓ FAQ
Q ReturnType<typeof fn> vs a hand-written return type?
A The extracted version always matches the implementation and never drifts; a hand-written type can express a more abstract intent (e.g. a named interface). Extract internally; name types explicitly at API boundaries.
Q Can I extract part of a union return type?
A Yes, by composing: ReturnType<typeof fn> yields the full return type, then refine it with Extract/NonNullable and friends. ReturnType is the raw extractor; downstream shaping goes to other utility types.
Q Can it extract a class method's return type?
A Yes: ReturnType<InstanceType<typeof MyClass>["methodName"]> — grab the instance type first, then index the method. In practice it is more common with standalone functions.