Guided Notes
TypeScript in Real Projects
Typing async code and API calls, runtime validation with zod, TypeScript with React and Node/Express, migrating JavaScript, linting, and team best practices.
Typing async code and APIs
Slide 1 / 5async function getUsers(): Promise<User[]> { const res = await fetch("/api/users"); if (!res.ok) throw new Error("HTTP " + res.status); return (await res.json()) as User[]; // ← an unchecked promise! }
Types vanish at runtime: the server could send anything. The as here is a guess. For data crossing a boundary (APIs, forms, files, env vars), validate at runtime.
