-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
Fix AvailableA PR has been opened for this issueA PR has been opened for this issueNeeds InvestigationThis issue needs a team member to investigate its status.This issue needs a team member to investigate its status.RescheduledThis issue was previously scheduled to an earlier milestoneThis issue was previously scheduled to an earlier milestone
Milestone
Description
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
Metadata
Metadata
Assignees
Labels
Fix AvailableA PR has been opened for this issueA PR has been opened for this issueNeeds InvestigationThis issue needs a team member to investigate its status.This issue needs a team member to investigate its status.RescheduledThis issue was previously scheduled to an earlier milestoneThis issue was previously scheduled to an earlier milestone
Type
Projects
Relationships
Development
Select code repository
Activity
jcalz commentedon Dec 6, 2020
Related to #39788
Awaited
type #53090