'How to force TypeScript to choose the correct method signature?

I'm experimenting with the parallelLimit() method from the async library, which has several signatures that depend on whether the third argument is passed or not, and so far this is a JS script, everything is fine:

const { parallelLimit } = async

new Promise(async () => {
  const tasks = Array(10)
    .fill(null)
    .map((item, i) => async () => i)
  const limit = 5
  await parallelLimit(tasks, limit)
    .then((results) => console.log(results.join(',')))
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/async/3.2.3/async.js"></script>

sfiddle-example-js

And then I try to use it in TypeScript:

npm i --save-dev @types/async

And TypeScript does not choose the correct signature,
but assumes that the method will return void.

How to solve this problem?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source