🔷 TypeScript Intermediate

What is the ReturnType utility type?

Why Interviewers Ask This

Candidates at the intermediate level are expected to not only know this concept but explain the trade-offs involved. Interviewers use this question to see if you can reason about design decisions, not just recall facts.

Answer

ReturnType<T> is a built-in utility type that extracts the return type of a function type T. It is implemented using conditional types and infer: type ReturnType<T extends (...args: any) => any> = T extends (...args: any) => infer R ? R : any. Usage: function getUserName(): string { return "Alice"; } type NameType = ReturnType<typeof getUserName>;NameType is string. This is powerful when you want to derive types from existing functions rather than writing them manually — the type is always in sync with the function. For async functions, it returns Promise<T>; combine with Awaited to unwrap: type Resolved = Awaited<ReturnType<typeof asyncFn>>. ReturnType is particularly useful for functions that return complex objects — infer the type from the function rather than duplicating the type definition.

Common Mistake

A common mistake is memorizing definitions without understanding implications. When asked this question, go one level deeper — explain what happens when this concept is misused or ignored.