TypeScript 7 reference · Utility Types
TypeScript Awaited<Type> Utility Type
Unwrap the value type of a Promise (recursively), like what await gives you. Awaited<Promise<number>> is number.
TypeScript 7 Since 4.5
Syntax
Awaited<Type>
Parameters
| Parameter | Description |
|---|---|
Type |
Usually a Promise<…> type. |
Return value
The resolved value type.
Examples
type A = Awaited<Promise<string>>; // string
type B = Awaited<Promise<Promise<number>>>; // number
const a: A = "ready";
const b: B = 42;
console.log(a, b);
Output
ready 42
async function loadUser() {
return { id: 1, name: "Ana" };
}
type User = Awaited<ReturnType<typeof loadUser>>;
const u: User = await loadUser();
console.log(u.name);
Output
Ana
Version history
| Version | Change |
|---|---|
| TypeScript 4.5 | Added |
Related
ReturnType<Type>· Get the return type of a function type, so other code can reuse it without repeating it.- TypeScript Utility Types · tutorial