For my TypeScript project, I came across a situation where I needed to utilize Promise.all(...)
to handle an array of multiple items:
Promise.all(
firstRequest,
secondRequest,
...,
nthRequest
)
.then((array : [FirstType, SecondType, ..., NthType]) => {
// process the responses here
});
The type definition
[FirstType, SecondType, ..., NthType]
was too long to include in the same block, so I attempted to define it separately and refer to it at that point.
I tried the following approach:
export interface ResponseParams {
[0]: FirstType;
[1]: SecondType;
...
[n]: NthType;
}
And then used it like this:
.then((array : ResponseParams) => {
// process the responses here
});
However, I encountered the error message:
Type 'ResponseParams' is not an array type.
Is there a way to externalize the type declaration to improve the cleanliness of my code?
Appreciate any insights. Thank you!