async.eachSeries and similar functions fail with TypeScript pollyfilled Promises. Only the first element in the collection is processed, and the loop never finishes. Setting the TypeScript compilerOptions.target config option to ES2017 or later resolves the issue.
Problem
What version of async are you using?
v3.2.5
Which environment did the issue occur in (Node/browser/Babel/Typescript version)
Node
What did you do? Please include a minimal reproducible case illustrating issue.
index.ts
import async from 'async'
async.eachSeries(['a', 'b', 'c'], async (item: string) => {
await Promise.resolve() // Something to do
console.log(item)
})
The promise from the first iteration of the loop never resolves, and the actual output is:
a
Solution
This issue is caused by the pollyfilled Promise implementation that TypeScript provides for the ES6 output target. Changing the target to ES2017 or later allows the use of native promises, which work as expected with the async library.
tl;dr
async.eachSeries
and similar functions fail with TypeScript pollyfilled Promises. Only the first element in the collection is processed, and the loop never finishes. Setting the TypeScriptcompilerOptions.target
config option toES2017
or later resolves the issue.Problem
What version of async are you using? v3.2.5
Which environment did the issue occur in (Node/browser/Babel/Typescript version) Node
What did you do? Please include a minimal reproducible case illustrating issue.
index.ts
tsconfig.json
Build and run the script:
What did you expect to happen?
Output should be:
What was the actual result?
The promise from the first iteration of the loop never resolves, and the actual output is:
Solution
This issue is caused by the pollyfilled Promise implementation that TypeScript provides for the ES6 output target. Changing the target to
ES2017
or later allows the use of native promises, which work as expected with the async library.