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
index.ts
and:
  1. Add explicit return types:
    • fetchUser(): Promise<User>
    • fetchProducts(): Promise<Array<Product>>
  2. Update loadData so it returns { user, products } after awaiting both helpers
  3. Export fetchUser, fetchProducts, and loadData
Fixtures already in the starter:
  • fetchUser resolves to { id: '1', name: 'Alice', email: 'alice@example.com' }
  • fetchProducts resolves to a non-empty product array (Laptop and Mouse)
Completion check: await loadData() returns { user: { id: '1', ... }, products: [...] } with at least one product.

Please set the playground first

Loading "Promise Types"
Loading "Promise Types"