CodePark/ questions / Utility types
START PRACTICINGPRACTICE
Frontend question · TypeScript › Utility types

What is R?

async function fetchUser() {
  return { id: 1, name: "Ann" };
}
type R = ReturnType<typeof fetchUser>;
Promise<{ id: number; name: string }>

The answer is Promise<{ id: number; name: string }>. An async function always returns a promise, and ReturnType gives exactly that promise type.

{ id: number; name: string } is the tempting wrong answer, because it is the object inside the promise. To get that resolved object, wrap it: Awaited<ReturnType<typeof fetchUser>>.