Promise<T>, async/await typing
Understand Promise shapes, annotate async functions, and work with awaited values safely.
Intro
Goal: Read and write Promise<T>-based code. You will type async functions, await values, and keep errors typed.
Promise basics
Promise<T> wraps an eventual value. Use Promise when no value resolves.
function delay(ms: number): Promise<void> {
return new Promise(resolve => setTimeout(resolve, ms));
}
const p: Promise<void> = delay(100);
p.then(() => console.log("done"));All lessons in this course
- Promise , async/await typing
- Error typing (unknown), narrowing in catch
- Concurrency patterns (all/settled/race) types