Typing Promises
A promise is typed as Promise<T>, where T is the value it fulfills with. TypeScript follows then, catch, and await and unwraps T. It does not run the promise.
Detailed Explanation
JavaScript promises are values that become a result later. TypeScript's job is to remember what that result is supposed to be. Promise<User> is a promise you expect to fulfill with a User. Promise<void> is a promise you expect to fulfill with nothing useful. Promise<never> is a promise that only rejects or never settles — rare and usually a mistake for a return type.
Inference reads return values. async function load() { return { id: "u1" }; } is Promise<{ id: string }>. An annotation Promise<User> checks that the returned object is a User. Forgetting return makes the function Promise<void>, which then fails to assign to Promise<User>.
.then(onFulfilled) is generic. The callback's return type becomes the next T, and if that return is a promise, it is flattened (the same as JS). .catch is historically typed loosely: the rejection reason is any in many lib versions, and the fulfillment type of the chain may widen to include the catch callback's return. Treat catch as a boundary. Prefer try/catch around await and type the catch as unknown.
Promise.all is typed as a tuple when the input is a tuple: Promise.all([loadUser(), loadCart()] as const) is [User, Cart] after await, not (User | Cart)[]. Without the tuple, you get an array union. Promise.allSettled is a discriminated union per slot: { status: "fulfilled"; value: T } | { status: "rejected"; reason: any }. Promise.race is a union of the member Ts.
Awaited<T> is the utility that recursively unwraps promises. It is what await does in the type system. Use it when you need to name that unwrap without writing async.
Nothing here validates the network. fetch().then(r => r.json()) is Promise<any>. Annotating the const as Promise<User> does not parse the JSON. Type the helper that validates, and let it return Promise<User>.
For the event-loop behavior of promises, see the JavaScript promises page. This page is the type wrapper around that behavior.
Code Examples
1. Annotate the fulfilled type; inference usually does it.
// 1. Annotate the fulfilled type; inference usually does it.
type User = { id: string; email: string };
async function loadUser(id: string): Promise<User> {
return { id, email: `${id}@example.com` };
}
const user = await loadUser("u1");
console.log(user.email);2. Promise.all on a tuple keeps slot types.
// 2. Promise.all on a tuple keeps slot types.
async function loadPage(id: string): Promise<{ user: User; title: string }> {
const [user, title] = await Promise.all([
loadUser(id),
Promise.resolve(`Hello ${id}`),
]);
return { user, title };
}3. allSettled is a discriminated union.
// 3. allSettled is a discriminated union.
const results = await Promise.allSettled([loadUser("u1"), loadUser("missing")]);
for (const result of results) {
if (result.status === "fulfilled") {
console.log(result.value.id);
} else {
console.log("rejected");
}
}Common Gotchas
Forgetting `return` in an `async` function yields `Promise<void>`
the error appears at the assignment to `Promise<User>`, not on the missing line, unless you annotated the function.
`res.json()` is `Promise<any>`
annotating the variable does not validate. Parse, then return.
`Promise.all` on an array of mixed promises is a union array
use a tuple (literal or `as const`) to keep per-slot types.
`.catch` reasons are often `any`
narrow with `unknown` in a `try/catch` instead.