I'm using TypeScript for a project and there's a case where I need to use Promise.all(...), which is returning an array of many items:
Promise.all(
firstRequest,
secondRequest,
...,
nthRequest
)
.then((array : [FirstType, SecondType, ..., NthType]) => {
// do things with response
});
Now, since the type [FirstType, SecondType, ..., NthType] is too long to be defined there, I wanted to define it elsewhere and use it in that point.
So I tried:
export interface ResponseParams {
[0]: FirstType;
[1]: SecondType;
...
[n]: NthType;
}
And:
.then((array : ResponseParams) => {
// do things with response
});
But I receive this error:
Type 'ResponseParams' is not an array type.
How can I externalise the type and make my code cleaner?
Thank you