If you're after a one-liner, I'm sorry to disappoint. Dereferencing assignment is meant for terse object expansion into variables, but not data-mapping between objects.
I would also encourage you to avoid clever code because if it's hard to read it's hard to understand which means it's hard to verify that it's working as expected for all appropriate edge cases.
In this case, adding more lines is trivially easy and clear:
const [a, b] = await Promise.all([first(), second()])
const x = {
a,
b
}
as a follow up question, what if you don't want to produce a
and b
variables within the current scope? For example, what if a
and b
are already defined and you need to avoid a naming conflict?
In that case, adding a little more code to be explicit is useful:
const [xA, xB] = await Promise.all([first(), second()])
const x = {
a: xA,
b: xB
}