Awaited
type Awaited<T> = T extends null | undefined ? T :
T extends object & { then(onfulfilled: infer F, ...args: infer _): any } ?
F extends ((value: infer V, ...args: infer _) => any) ?
Awaited<V> :
never :
T;Compute the type of awaiting T. Promises and thenables are unwrapped recursively; non-thenable types are unchanged. This is a type alias, not a runtime await.
| Type parameter | Description |
|---|---|
T | Usually a Promise type, an async function's return type, or a union that includes a thenable. Plain types such as number are returned as themselves. |
Produces: The awaited type. For Promise<Promise<string>> this is string. For number this is number.
Type errors
type error— Assigning a value that does not match the unwrapped type is a type error. Awaited does not loosen the fields of the resolved value.
- The signature is the declaration from TypeScript 5.9.3's lib.es5.d.ts, formatted for reading. See that file for the inline comments on thenables.
- Promise.resolve(Promise.resolve("done")) is typed as Promise<string>, not Promise<Promise<string>>, because Promise.resolve flattens thenables at the type level too.
async function load(): Promise<{ id: number }> {
return { id: 1 };
}
type Loaded = Awaited<ReturnType<typeof load>>;
type Nested = Awaited<Promise<Promise<string>>>;
type Plain = Awaited<number>;
const loaded: Loaded = { id: 1 };
const nested: Nested = "ok";
const plain: Plain = 7;
// @ts-expect-error Awaited unwraps the Promise, not the field types inside the value
const wrong: Loaded = { id: "1" };
async function main() {
const value: Loaded = await load();
console.log(loaded.id, nested, plain, value.id);
}
main();Expected output
1 ok 7 1Related: JavaScript Promise reference, Official Awaited