Destructuring bluebird Promise.all([..])
See original GitHub issueHi folks, I’m hoping someone can help with this. I have a fairly common pattern in my code of using array destructuring to name the results of await Promise.all([])
. Example:
async function foo() {
const [a, b] = await Promise.all([
Promise.resolve(1),
Promise.resolve('b'),
]);
}
(I’m using bluebird here). Running this through flow I get a bunch of errors that I don’t fully understand, but it looks like flow is not able to treat the awaited result of Promise.all([]) as a tuple?
foo.js:6
6: const [a, b] = await Promise.all([
^ Bluebird$Promise. This type is incompatible with
606: declare function $await<T>(p: Promise<T> | T): T;
^^^^^^^^^^^^^^ union: type application of identifier `Promise` | type parameter `T` of await. See lib: /private/tmp/flow/flowlib_3ae7518b/core.js:606
Member 1:
606: declare function $await<T>(p: Promise<T> | T): T;
^^^^^^^^^^ type application of identifier `Promise`. See lib: /private/tmp/flow/flowlib_3ae7518b/core.js:606
Error:
6: const [a, b] = await Promise.all([
^ Bluebird$Promise. This type is incompatible with
606: declare function $await<T>(p: Promise<T> | T): T;
^^^^^^^^^^ Promise. See lib: /private/tmp/flow/flowlib_3ae7518b/core.js:606
Member 2:
6: const [a, b] = await Promise.all([
^ type parameter `T` of await
Error:
6: const [a, b] = await Promise.all([
^ element 0. Indexable signature not found in
6: const [a, b] = await Promise.all([
^ Bluebird$Promise
Any help (or workarounds) would be much appreciated!
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
.spread | bluebird
Bluebird is a fully featured JavaScript promises library with unmatched performance.
Read more >Promise.all(...).spread is not a function when ... - Stack Overflow
I'll make my comment into an answer since it solved your issue. .spread() is not a standard promise method. It is available in...
Read more >[Solved]-Promise.all(...).spread is not a function when running ...
You can include the Bluebird promise library so you have access to .spread() . var Promise = require('bluebird');. Use destructuring in the callback ......
Read more >.spread() - Bluebird - W3cubDocs
all () but the ES6 destructuring syntax doesn't, hence the manual .all() call in the above code. If you want to coordinate several...
Read more >JavaScript Async/Await Promise All Array Destructuring
I think you will agree with me when I say working with asynchronous code is an important part of modern app development.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
facebook/flow#2171
I use:
The problem here is that an
async
function needs to be able toawait
any “thenable”. Here is an example of what should be accepted by flow:Here’s a basic “thenable” being
await
ed inside anasync
function on node 7 with the--harmony-async-await
flag: