"A Promise is a typed wrapper around a value that doesn't exist yet."
What Promise<T> describes
Promise<T> is a generic type that represents a value of type T that will be available later. The Promise has three states (pending, fulfilled, rejected); the type captures only the fulfilled value's type. Rejection is untyped — TypeScript can't predict what kind of error will be thrown.
You produce a Promise<T> via:
- An async function (
async function f(): Promise<User> { return getUser() }) new Promise<T>((resolve, reject) => ...)Promise.resolve(value)orPromise.reject(error)- Library calls like
fetch(),fs.readFile(), etc.
Consuming a Promise
Two ways: .then(callback) chains or await inside an async function. fetchUser().then(user => user.name) and const user = await fetchUser(); user.name are equivalent. The async/await form is generally preferred — it's flatter, easier to read, and integrates with try/catch.
The composition pattern
Async functions compose naturally. async function load(): Promise<Profile> can call other async functions, await them, and return a derived value. The Promise wrapper survives across all the steps; only at the topmost call do you unwrap it (with await or .then).
Promise<T> is the type of 'a future value of type T'. Reading async code as 'this is the type after you await' is the model that makes the rest of the track easy.