Codectionary / Developer documentation / TypeScript

Unwrapping Async Results with Awaited

Awaited<T> models the resolved type of an await operation, including nested promises and compatible thenables. Introduced in TypeScript 4.5, it is commonly combined with ReturnType to derive a loader’s resolved result without repeating its data model.

Syntax

type Data = Awaited<ReturnType<typeof load>>;

Examples

Unwrapping Async Results with Awaited: working example

Run this standalone example after compiling with TypeScript 5.4+ in strict mode, targeting ES2022. Expected result: The program prints Ada: 9.

async function load() { return { name: "Ada", score: 9 }; }
type Data = Awaited<ReturnType<typeof load>>;
function format(data: Data): string { return `${data.name}: ${data.score}`; }
async function main() {
  console.log(format(await load()));
}
void main();
  1. Expected result: The program prints Ada: 9.
  2. ReturnType alone produces the promise type.
  3. Awaited extracts the value consumed after awaiting the loader.

Best practices

  • Derive helper types from the real async API when it owns the shape.
  • Remember that Awaited does not model rejection payloads as a separate checked type.

Runtime & versions

Compiled to JavaScript. Feature availability depends on the language and runtime version used by your project; consult the official reference below.

TypeScript Handbook

Specifications & further reading