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();- Expected result: The program prints Ada: 9.
- ReturnType alone produces the promise type.
- 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