Question presented to candidate:
"What is the Awaited utility type? Why did TypeScript add it when T extends Promise<infer U> ? U : T already existed, and where do you use it?"
What a strong answer should cover:
Awaited<T>is the type you get fromawaiton aT: it unwraps promises recursively, unwraps any thenable (an object with a callablethen), and leaves non-promise types unchanged- It distributes over unions:
Awaited<boolean | Promise<number>>isboolean | number - Common use:
Awaited<ReturnType<typeof fn>>for the resolved value of an async function; library typings such asPromise.alluse it so tuples keep each slot type - It was added in TypeScript 4.5; a one-level
inferversion leavesPromise<string>behind for nested promises - Generic code:
awaiton aTgivesAwaited<T>, and an inferred generic async return type can be wrong, so annotatePromise<Awaited<T>>
Code / implementation expected: Optional β Awaited<ReturnType<...>>, or a hand-written recursive version.