DEV Community

[Comment from a deleted post]
Collapse
 
peq profile image
Peter Zeller • Edited

That looks really ugly to me. You have to read it left, right, left right, left, right.

You'll probably also lose all typing information if you do it like this (although TypeScript already can type a lot of stupid Javascript idioms).

Collapse
 
djheru profile image
Philip Damra • Edited

It's not a stupid idiom, it's just passing an array to an async function and receiving an array as a return value. If it's easier for you, you can type

const getAllStatesPromise = GetAllStates();
const fetchAddressTypesPromise = FetchAddressTypes();
const findPhoneTypesPromise = FetchPhoneTypes();

const promisesToAwait = [
  getAllStatesPromise, 
  fetchAddressTypesPromise, 
  findPhoneTypesPromise 
];

const resolvedPromises = await Promise.all(promisesToAwait);

const states = resolvedPromises[0];
const addressTypes = resolvedPromises[1];
const phoneTypes = resolvedPromises[2];

but why would you want to do that???