TypeScript Types and Generics/Use `ReturnType<T>`

Extract a function’s return type.

Section: Utility Types

Use `ReturnType<T>`

typescript
typescript
function createUser() {
  return { id: 1, name: "Ada" };
}

type User = ReturnType<typeof createUser>;
Explanation

Useful when you want a type that stays synced with a function implementation.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Utility Types
Use `Partial<T>`
Make every property optional.
OpenIn sheettypescriptsame section
Use `Required<T>`
Make all properties required.
OpenIn sheettypescriptsame section
Use `Pick<T, K>`
Select a subset of properties.
OpenIn sheettypescriptsame section
Use `Omit<T, K>`
Remove properties from a type.
OpenIn sheettypescriptsame section
Use `Record<K, T>`
Type objects whose keys all map to the same value type.
OpenIn sheettypescriptsame section
Use `Awaited<T>`
Unwrap the resolved type of a promise-like value.
OpenIn sheettypescriptsame section