Promise Types
Promise Types
π¨βπΌ Let's ensure our async functions have proper type annotations. This helps
TypeScript catch errors and makes our code more maintainable.
type Episode = { id: string; title: string }
async function fetchEpisode(): Promise<Episode> {
return { id: 'e1', title: 'Pilot' }
}
async function fetchEpisodeIds(): Promise<Array<string>> {
return ['e1', 'e2']
}
π¨ Open
and:
- Add explicit return types:
fetchUser(): Promise<User>fetchProducts(): Promise<Array<Product>>
- Update
loadDataso it returns{ user, products }after awaiting both helpers - Export
fetchUser,fetchProducts, andloadData
Fixtures already in the starter:
fetchUserresolves to{ id: '1', name: 'Alice', email: 'alice@example.com' }fetchProductsresolves to a non-empty product array (Laptop and Mouse)
Completion check:
await loadData() returns
{ user: { id: '1', ... }, products: [...] } with at least one product.

