Recursively unwrap Promise types to get the resolved value type.
The Awaited utility type recursively unwraps Promise and PromiseLike types to extract the type of the value they resolve to. For non-Promise types, it returns the type unchanged. This mirrors the behavior of the await keyword at the type level.
Awaited handles nested promises correctly, unwrapping multiple layers in a single step. For example, Awaited<Promise<Promise<string>>> resolves to string, matching the runtime behavior where await automatically flattens nested promises.
This utility type was introduced in TypeScript 4.5 and is particularly useful for typing the results of async operations, generic async utilities, and libraries that work with promise-based APIs.
type A = Awaited<Promise<string>>; // string
type B = Awaited<Promise<Promise<number>>>; // number
type C = Awaited<string>; // string
async function fetchData(): Promise<string> {
return 'data';
}
type Data = Awaited<ReturnType<typeof fetchData>>; // string