Skip to content

TS 4.2 Promise.all can't deal with array + spread #43157

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bfricka opened this issue Mar 9, 2021 · 0 comments
Closed

TS 4.2 Promise.all can't deal with array + spread #43157

bfricka opened this issue Mar 9, 2021 · 0 comments

Comments

@bfricka
Copy link

bfricka commented Mar 9, 2021

Bug Report

🔎 Search Terms

  • no overload matches call created:>=2021-01-01
  • promise created:>=2021-01-01
  • iterable created:>=2021-01-01

🕗 Version & Regression Information

  • 4.2.2
  • 4.2.3
  • Still reproduces in nightly 4.3.0-dev.20210308
  • Works fine in 4.1 and below
  • This changed between versions 4.1.5 and 4.2

⏯ Playground Link

Playground link with relevant code

💻 Code

const arrFoo = async () => ['foo']
const foo = async () => 'foo'
const bar = async () => 'bar'

const test = async () => {
    const mapToBarPromises = [1, 2, 3].map(bar)
    
    const onlyBars = await Promise.all(mapToBarPromises)
    const onlyBarsSpread = await Promise.all([...mapToBarPromises])
    const mixed = await Promise.all([foo(), bar()])
    const mixedWithArr = await Promise.all([arrFoo(), bar()])
    const mixedWithSpread = await Promise.all([foo(), ...mapToBarPromises])
    // Fail when mixing spread with other arrays
    const mixedArrAndSpread = await Promise.all([arrFoo(), ...mapToBarPromises])
}

🙁 Actual behavior

TypeScript 4.2 Promise.all can't deal with a Promise<T1[]> plus a spread Promise<T2>

🙂 Expected behavior

This shouldn't be an error and in previous versions, it wasn't. Since it's very common for something async to return a list it makes it painful to do something like:

const [teams, ...players] = await Promise.all([getTeams(), ...regions.map(getPlayers)])

Sorry, I couldn't think of a less contrived example. More likely in code I see, the spread is a list of side effects updates, where we don't actually care about the result:

await Promise.all([
  updateUsers(),
  ...teams.map(updateTeam),
])

I can do Promise.all<any>(), but if we actually want the values, we have to do some elaborate typing that we shouldn't have to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant