Sometimes, we want to use Promise.all()
with TypeScript.
In this article, we’ll look at how to use Promise.all()
with TypeScript.
How to use Promise.all() with TypeScript?
To use Promise.all()
with TypeScript, we can use it as we do with JavaScript.
For instance, we write
const [foo, bar] = await Promise.all([fooPromise, barPromise]);
in an async function.
We call Promise.all
to return a promise with an array of the resolved values from the array of promises we passed into Promise.all
.
The TypeScript compiler will infer the type automatically and make sure they’re consistent between both objects so we don’t have to specify them ourselves.
Conclusion
To use Promise.all()
with TypeScript, we can use it as we do with JavaScript.