Awaited
Concept and syntax
Awaited<T> models recursive unwrapping of promise-like results and distributes over unions. It is a type-level model of awaiting, not a scheduler or a promise constructor. It preserves non-promise values such as boolean.
Working example
Save each snippet separately as main.ts in a fresh directory with TypeScript 5.8.3. Compile with tsc --strict --target ES2022 --module commonjs --moduleDetection force --skipLibCheck --noEmitOnError main.ts and run accepted snippets with node main.js. Type aliases are erased; assignments and diagnostic checks demonstrate the type relations, not the printed output alone.
type Res=Awaited<Promise<Promise<number>>|boolean>; async function run(){const n:Res=await Promise.resolve(7); console.log(n); }run();Expected output:
7Common mistake
Intentionally invalid; compile separately and do not execute.
type Res=Awaited<Promise<Promise<number>>|boolean>; async function run(){const n:Res=await Promise.resolve(7); console.log(n); }const n:Res="seven";Expected diagnostic: TS2322. The unwrapped union is number | boolean.
Practice and recap
Compare Awaited<null> and Awaited<Promise<string>>.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Awaited — knowledge check
Check the type transformation, trace output, diagnose a rejected example, and apply the concept to a new case.
Which statement about Awaited is accurate?
What is the complete stdout, represented as a JSON string (including newline characters)?
type Res=Awaited<Promise<Promise<number>>|boolean>; async function run(){const n:Res=await Promise.resolve(7); console.log(n); }run();Which diagnostic and explanation match the rejected example under the lesson settings?
type Res=Awaited<Promise<Promise<number>>|boolean>; async function run(){const n:Res=await Promise.resolve(7); console.log(n); }const n:Res="seven";What is Awaited<boolean | Promise<string>>?