You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Potential regression in 4.2 - Calling .map on T[] | Y[] is now callable but leads to an implicit any errorΒ #42646
changed the title [-]Potential regression in 4.2 - Calling `.map` on `T[] | Y[]` is now callback but leads to an implicit any error[/-][+]Potential regression in 4.2 - Calling `.map` on `T[] | Y[]` is now callable but leads to an implicit any error[/+]on Feb 4, 2021
It's not a regression (definitionally, going from can't call at all to implicitly any is a less restrictive error - now you can explicitly annotate it and actually resolve the call), and we already have #42620 open to improve the experience further~
every and filter have multiple overloads (with differing numbers of type parameters) which makes the union call difficult to resolve, while map only has one overload, so combining the signatures is much more straightforward.
Not in the immediate future, no. The readonly-ness isn't what matters for our ability to check it - the overload count/genericness of the signature is. We've been slowly expanding how much of that we can check, but I can't make any claims as to how far we'll go or by when.
I see, thanks. For some reason, I thought these methods are disallowed because of type safety. E.g., what can be pushed to an array if it's type is string[] | number[]? So it looked like readonly-ness might help. But now I see I misunderstood the problem.
Anyway, wouldn't it be a helpful trick to implicitly transform readonly string[] | readonly number[] to readonly (string | number)[] for the purposes of signature merging?
Tom Sherman (@tom-sherman) Previously, such calls were disallowed because merging signatures for generic overloaded functions is a tricky procedure, and it wasn't implemented. Now, in some cases, it became possible. After merging that PR, it'll be possible in more cases. Hopefully, we'll read more on that in the release blog post.
This expression is not callable.
Each member of the union type '{ <S extends TSType>(predicate: (value: TSType, index: number, array: TSType[]) => value is S, thisArg?: any): this is S[]; (predicate: (value: TSType, index: number, array: TSType[]) => unknown, thisArg?: any): boolean; <S extends TSType>(predicate: (value: TSType, index: number, array: TSType[]) => value is S, thi...' has signatures, but none of those signatures are compatible with each other.(2349)
Activity
[-]Potential regression in 4.2 - Calling `.map` on `T[] | Y[]` is now callback but leads to an implicit any error[/-][+]Potential regression in 4.2 - Calling `.map` on `T[] | Y[]` is now callable but leads to an implicit any error[/+]weswigham commentedon Feb 4, 2021
It's not a regression (definitionally, going from can't call at all to implicitly any is a less restrictive error - now you can explicitly annotate it and actually resolve the call), and we already have #42620 open to improve the experience further~
thorn0 commentedon Feb 4, 2021
But why does it allow specifically
map(andsome)?everyandfilterare still errors.related issue: #35045
weswigham commentedon Feb 4, 2021
everyandfilterhave multiple overloads (with differing numbers of type parameters) which makes the union call difficult to resolve, whilemaponly has one overload, so combining the signatures is much more straightforward.thorn0 commentedon Feb 4, 2021
Is there any chance for
everyto work for unions of read-only array types in the foreseeable future?weswigham commentedon Feb 4, 2021
Not in the immediate future, no. The
readonly-ness isn't what matters for our ability to check it - the overload count/genericness of the signature is. We've been slowly expanding how much of that we can check, but I can't make any claims as to how far we'll go or by when.thorn0 commentedon Feb 4, 2021
I see, thanks. For some reason, I thought these methods are disallowed because of type safety. E.g., what can be
pushed to an array if it's type isstring[] | number[]? So it looked like readonly-ness might help. But now I see I misunderstood the problem.thorn0 commentedon Feb 4, 2021
Anyway, wouldn't it be a helpful trick to implicitly transform
readonly string[] | readonly number[]toreadonly (string | number)[]for the purposes of signature merging?tom-sherman commentedon Feb 4, 2021
Wesley Wigham (@weswigham) It's not clear to me how your PR relates to this issue, do you have a playground link I can poke around with?
thorn0 commentedon Feb 4, 2021
Tom Sherman (@tom-sherman) Previously, such calls were disallowed because merging signatures for generic overloaded functions is a tricky procedure, and it wasn't implemented. Now, in some cases, it became possible. After merging that PR, it'll be possible in more cases. Hopefully, we'll read more on that in the release blog post.
thorn0 commentedon Aug 26, 2022
Now that it works for
map, I wonder if this issue should be renamed with a mention offilterandeveryin the title, That'd make it more discoverable.thorn0 commentedon Aug 26, 2022
An isolated real-world case to demo how this issue is a pain:
playground
everycauses the following error:jakebailey commentedon Jun 20, 2023
Closing as fixed in #53489; reading the PR, it has this case as a test.