It's common knowledge that Promise.all will return settled promises in the same order of the requested iterable.
I'm currently grappling with how to correctly define types for individual settled resolves. I am utilizing Axios for handling asynchronous calls.
Promise.all([
<void, A>call an API a with response type A,
<void, B>call another API b with response type B,
<void, C>call another API c with response type C
]).then(([
Response aa of type A: ?,
Response bb of type B: ?,
Response cc of type C: ?
]) => {
});
All responses are of type AxiosResponse<A | B | C>
. However, explicitly setting it to this may cause problems when trying to access a property that doesn't exist in all response types, leading to errors like bb.test
.
Is it possible to specify the type of each individual response like this?
]).then(([
Response aa of type A: AxiosResponse<A>,
Response bb of type B: AxiosResponse<B>,
Response cc of type C: AxiosResponse<C>
]) => {
Note: The compiler is handling the types implicitly as well.