For more information, you can check out this post on Stack Overflow: How to use Promise.all() with Typescript
In my TypeScript project, I am trying to implement Promise.all().
I have an array of promises that I pass to Promise.all(), then use .then() to handle the responses.
However, when I try to use .map() on the responses later in the code, TypeScript shows an error message stating "Property 'map' does not exist on type 'void | any[]'". This issue arises regardless of which array method I use.
The problem seems to be that TypeScript expects Promise.all() to potentially return void instead of an array of any[].
Here is a sample code snippet where Axios is used to make three requests:
const requests = [1, 2, 3].map((request) =>
axios.get(`http://localhost:3000/test${request}`)
);
const promises = await Promise.all(requests)
.then((responses) => responses.map((response) => response.data))
.catch(({ message }) => console.log(message));
// further down...
const responses = promises.map(promise => promise.hello);
The error "Property 'map' does not exist on type 'void | any[]'. Property 'map' does not exist on type 'void'.ts(2339)" occurs at the last line.
Is there a way to inform the compiler that the result of my Promise.all() will be an array?