-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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 and Promise.allSettled infer incorrect types from Array subclasses #51993
Comments
This would break tuples, which (I assume), are more common use case than Array subclasses in promise methods. |
Yeah, we definitely can’t break tuple inference here. Seems like there could be another way to write it, but we’ll have to weigh the complexity and performance cost against how useful it actually is on average in real code. |
Extending Array class, while uncommon is part of the language and this bug can be a wall against libraries development, for example. I'm going to spend some time in finding a solution as soon as I get the chance! |
While I didn't test this exhaustively, It looks like it's working declare function all<T extends [unknown] | ArrayLike<unknown> | Iterable<unknown>>(values: T): Promise<
T extends {[P in 0]: unknown} ?
{-readonly [P in keyof T]: Awaited<T[P]>} :
T extends ArrayLike<infer S> | Iterable<infer S> ? Awaited<S>[] : never
> |
lib Update Request
Configuration Check
My compilation target is
ES2020
and my lib isthe default
.Missing / Incorrect Definition
Promise.all
Promise.allSettled
Sample Code
Playground link
Documentation Link
Promise.all
Promise.allSettled
Possible fix
The inferred value should be of type
number[]
exactly like what happens with normalArray
class. In the linked playground, It can be seen thatPromise.all
andPromise.allSettled
infer the correct type with anIterable
type of object. This undesired behavior just happens withArray
subclasses. I have quickly tried changing the signature from the original:to
and it works as expected: Playground link
The text was updated successfully, but these errors were encountered: