🔷 TypeScript Intermediate

What is the Awaited utility type in TypeScript?

Why Interviewers Ask This

Mid-level TypeScript roles require deep understanding of this topic. Interviewers ask this to separate candidates who truly understand the mechanics from those who only know surface-level concepts.

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.

Common Mistake

Rushing to answer is a common mistake. Take two seconds to structure your response: definition → example → trade-off. This structure makes complex TypeScript answers easy to follow.