Skip to content
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

Promise.all overloads don't account for single element tuples #41831

Closed
gigobyte opened this issue Dec 5, 2020 · 1 comment · Fixed by #53090
Closed

Promise.all overloads don't account for single element tuples #41831

gigobyte opened this issue Dec 5, 2020 · 1 comment · Fixed by #53090
Assignees
Labels
Fix Available A PR has been opened for this issue Needs Investigation This issue needs a team member to investigate its status. Rescheduled This issue was previously scheduled to an earlier milestone

Comments

@gigobyte
Copy link
Contributor

gigobyte commented Dec 5, 2020

TypeScript Version: 4.2.0-dev.20201205

Search Terms: Promise.all, tuple, readonly

Code

// readonly [Promise<number>]
const promises = [Promise.resolve(0)] as const

Promise.all(promises).then((results) => {
  const first = results[0]
  const second = results[1]
})

Expected behavior:

const promises = [Promise.resolve(0)] as const

Promise.all(promises).then((results) => { // results is [number]
  const first = results[0] // number
  const second = results[1] // Tuple type '[number]' of length '1' has no element at index '1'
})

Actual behavior:

const promises = [Promise.resolve(0)] as const

Promise.all(promises).then((results) => { // results is number[]
  const first = results[0] // number | undefined (if noUncheckedIndexedAccess is on)
  const second = results[1] // no errors here
})

This is because of the last overload in lib.es2015.promise.d.ts:

all<T>(values: readonly (T | PromiseLike<T>)[]): Promise<T[]>;

Tuples with more than 1 element have expected behavior.

Playground Link: Here

Related Issues: Couldn't find any

@jcalz
Copy link
Contributor

jcalz commented Dec 6, 2020

Related to #39788

@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Dec 10, 2020
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 4.2.1 milestone Dec 10, 2020
@RyanCavanaugh RyanCavanaugh added the Rescheduled This issue was previously scheduled to an earlier milestone label Mar 4, 2021
@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Mar 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fix Available A PR has been opened for this issue Needs Investigation This issue needs a team member to investigate its status. Rescheduled This issue was previously scheduled to an earlier milestone
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants