Skip to main content
Module 8 · Lesson 2 of 316/22 in the course~16 min
Module lessons (2/3)

Typed Concurrency: Promise.all, allSettled and race

Lesson preview5 hands-on exercises readyCourse TypeScript · Module 8 — TypeScript Asynchronous & Promise

Take advantage of the tuple inference of Promise.all and manage partial outcomes with PromiseSettledResult<T>.

What you'll learn in this lesson

  • Leverage heterogeneous tuple inference of Promise.all([pA, pB]) to obtain distinct types for each element.
  • Include the discriminated union PromiseSettledResult<T> in Promise.allSettled and filter the results with status === 'fulfilled'.
  • Model typed timeouts by combining Promise.race and checked status or error types.
  • Choose clearly between sequential (await in loop) and concurrent (all / allSettled) based on failure management.

Overview

Launching independent calls back to back with multiple await doubles or triples the latency unnecessarily. Promise's static combinators perform operations in parallel, and TypeScript exactly preserves the type of each branch involved.

By passing a literal list [fetchUser(), fetchOrders()] to Promise.all, TypeScript infers a tuple of distinct types, not a mixed array!

Sections covered in this lesson

  1. 1Promise.all: heterogeneous tuple inference
  2. 2Promise.allSettled: failsafe with native Narrowing
  3. 3Promise.race and Promise.any
  4. 4Guided practice
  5. 5Check for understanding
Pro Lesson · Module 8 — TypeScript Asynchronous & Promise

Unlock "Typed Concurrency: Promise.all, allSettled and race" and the full Course TypeScript curriculum

Take advantage of the tuple inference of Promise.all and manage partial outcomes with PromiseSettledResult<T>.

Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.

  • Instant access to all advanced modules in Course TypeScript plus 17 more courses
  • Hands-on browser exercises with automated test suites and solutions
  • 14-day money-back guarantee processed via Paddle.com

14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.