Promise.allKeyed: A Safer, Named‑Result Alternative to Promise.all

The article examines the long‑standing array‑order pitfall of Promise.all, explains how the TC39 Stage‑3 Await Dictionary proposal introduces Promise.allKeyed to return objects keyed by name, and shows why this change improves readability, reduces hidden bugs, and fits TypeScript better.

Full-Stack Cultivation Path
Full-Stack Cultivation Path
Full-Stack Cultivation Path
Promise.allKeyed: A Safer, Named‑Result Alternative to Promise.all

Promise.all’s Core Problem: Array‑Index Trap

Developers often write code like:

const [user, company] = await Promise.all([
  fetchUser(),
  fetchCompany()
]);

Here the mapping between each promise and its result is implicit in the array position. If the order of the promises changes, the destructuring still succeeds but the variables receive the wrong data:

const [user, company] = await Promise.all([
  fetchCompany(),
  fetchUser()
]);
// user now contains company data, company contains user data

This silent bug is especially dangerous in large pages that load many independent resources:

const [user, permissions, orders, products, settings] = await Promise.all([
  getUser(),
  getPermissions(),
  getOrders(),
  getProducts(),
  getSettings()
]);

Developers must constantly remember the hidden convention “0 → user, 1 → permissions, …”. The larger the project, the higher the maintenance cost.

Enter Promise.allKeyed

The new proposal, Promise.allKeyed(), simply returns an object instead of an array:

const { user, company } = await Promise.allKeyed({
  user: fetchUser(),
  company: fetchCompany()
});
// Result: { user: UserData, company: CompanyData }

Now each result is directly bound to its name, eliminating the reliance on order.

Await Dictionary – The TC39 Proposal Behind It

The change originates from the TC39 “Await Dictionary” proposal, currently at Stage 3. TC39 is the JavaScript standards committee. A proposal progresses through Stage 0 → Stage 1 → Stage 2 → Stage 3 (candidate) → Stage 4 (final). Reaching Stage 3 means the API design is largely stable and close to becoming part of the ECMAScript specification.

Why JavaScript Needs This Feature

Developers have already built similar utilities. For example:

async function combinePromises(obj) {
  const entries = await Promise.all(
    Object.entries(obj).map(async ([key, promise]) => [
      key,
      await promise
    ])
  );
  return Object.fromEntries(entries);
}

const result = await combinePromises({
  user: fetchUser(),
  company: fetchCompany()
});

The proposal essentially adds a built‑in object‑mapping layer to Promise.all.

Will Promise.all Disappear?

Not in the short term. Promise.all() remains ideal for:

Batch execution of homogeneous tasks

Processing collections of the same type of data

Scenarios where an array naturally represents the data

For example, updating a list of users:

await Promise.all(users.map(updateUser));

However, when loading multiple distinct pieces of business data (user info, permissions, orders, settings, recommendations, etc.), an object shape is far clearer.

Benefits of Promise.allKeyed

Eliminates dependence on array order

Reduces hidden bugs caused by mismatched positions

Improves code readability

Aligns naturally with TypeScript’s type system

Looking Ahead

If the proposal reaches ECMAScript, many front‑end codebases could shift from:

const [a, b, c] = await Promise.all([]);

to:

const { a, b, c } = await Promise.allKeyed({});

After a decade of using the array‑based Promise pattern, JavaScript may finally get a small but meaningful upgrade.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

TypeScriptJavaScriptAPI designasyncPromiseTC39
Full-Stack Cultivation Path
Written by

Full-Stack Cultivation Path

Focused on sharing practical tech content about TypeScript, Vue 3, front-end architecture, and source code analysis.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.