1// Chained promises — return the next promise to keep the chain alive
2// learning module: fetch a user, type the result
3
4type User = { id: number; name: string }
5
6export function fetchUser(id: number) {
7 return fetch("/api/users/" + id)
8 .then((response) => {
9 if (!response.ok) {
10 throw new Error("Failed")
11 }
12 return response.json() // ← this line
13 })
14 .then((data) => data as User)
15}