0Pricing
TypeScript Academy · Lesson

Concurrency patterns (all/settled/race) types

Model concurrency with Promise.all / allSettled / race, understand their result types, and build safe helpers.

Intro

Goal: Run tasks concurrently with Promise.all, handle mixed outcomes via allSettled, and use race for timeouts/fallbacks. Learn the types each returns.

all: tuple types

Promise.all with a tuple preserves element types and order; each element is awaited to its inner type.

async function one(): Promise<number> { return 1 }
async function two(): Promise<string> { return "two" }

async function runAll() {
  const [a, b] = await Promise.all([one(), two()]);
  // a: number, b: string
  console.log(a + 1, b.toUpperCase());
}

runAll();

All lessons in this course

  1. Promise , async/await typing
  2. Error typing (unknown), narrowing in catch
  3. Concurrency patterns (all/settled/race) types
← Back to TypeScript Academy