🔷 TypeScript Intermediate

What is the Awaited utility type in TypeScript?

Answer

Awaited<T> (TypeScript 4.5) recursively unwraps Promise types to get the resolved value type. It handles nested promises and thenables. Example: type A = Awaited<Promise<string>>; — result is string. Nested: type B = Awaited<Promise<Promise<number>>>; — result is number. This type replaces older patterns like ReturnType<typeof fn> extends Promise<infer T> ? T : never. Common use case: type ApiResult = Awaited<ReturnType<typeof fetchUser>>; — gets the actual resolved type of an async function's return. Before Awaited, getting the type of an awaited async function result required verbose conditional type expressions. Awaited is used internally in TypeScript's type for Promise.all() — it can correctly type the resolved array even with mixed promise and non-promise values in the input tuple.