function-types

ReturnType<T>

Infers the return type of a function type T using `infer R`. Widely used to derive types from existing functions without redeclaring them.

type ReturnType<T extends (...args: any) => any> = T extends (...args: any) => infer R ? R : any

Usage patterns

Pattern Purpose
ReturnType<typeof fn> Get a value's function return type via typeof
Awaited<ReturnType<T>> Get the resolved type for async functions
ReturnType<T> extends Promise<infer R> ? R : ReturnType<T> Manual async unwrap (pre-Awaited)
infer R The inference site that names the return type

Examples

function greet() { return 'hi' as const; }
type G = ReturnType<typeof greet>;

Result: 'hi'

async function load() { return { ok: true }; }
type Loaded = Awaited<ReturnType<typeof load>>;

Unwraps the Promise to { ok: boolean }

type Handler = (e: Event) => void;
type R = ReturnType<Handler>;

Result: void

type BadReturn = ReturnType<string>; // Error

T must be a function type — non-function inputs error at compile time

Gotcha

For overloaded functions, ReturnType only picks the last overload signature. For async functions it gives Promise — wrap with Awaited if you want X.

Related utility types

← All TS utility types · TypeScript vs JavaScript · any vs unknown vs never