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.

GroupUtility Types
KindType
Strict modeNot 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

TA 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.
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.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏