-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug
Description
TypeScript Version: 3.0.0-dev.201xxxxx
Search Terms:
promise.all
Code
First off, idk if this can be considered a bug or an improvement.
The code is legit but it's probably not what you intended to write or what you would expect to look at when you have to debug JS code.
Basically the code wanted to await a bunch of Promises via Promise.all but the Promises array was accidentally nested:
let delay = (delay: number) => {
return new Promise(resolve => {
window.setTimeout(() => {
console.log("done: ", delay)
resolve();
}, delay);
})
}
let delays = [1000, 2000];
(async () => {
console.log("start");
await Promise.all([delays.map(ms => delay(ms))]);//accidentally nested promises array
console.log("end");
})();Expected behavior:
"start"
"done: 1000"
"done: 2000"
"end"
Actual behavior:
"start"
"end"
"done: 1000"
"done: 2000"
which is of course correct but probably not what you intended to write.
It would be nice if TypeScript could pick this up and report it.
Related Issues:
Metadata
Metadata
Assignees
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug