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 type annotations to all async functions
  2. Use Promise<T> to type the return values
  3. Ensure the types match what the functions actually return
🦺 TypeScript will infer Promise types, but explicit annotations make your intent clear and help catch errors early.

Please set the playground first

Loading "Promise Types"
Loading "Promise Types"
Login to get access to the exclusive discord channel.
Loading Discord Posts