-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Missing overload method on union types #60006
Comments
There doesn't seem to be a reason to write But I kind of thought #53489 took care of these "union of array" things. |
true that, thanks for pointing that out. I initially wrote the function for |
You're reporting this issue specifically? function groupBy<T>(array: Array<T> | ReadonlyArray<T>) {
array.reduce<any>((acc, element) => {
throw new Error();
});
} |
@RyanCavanaugh yes the code sample can be reduced to that |
This was released in TS 5.2 and it's only about fallback signatures. It applies to situations when a signature can’t be found in a normal way but we can see that TS was able to find some signatures here even before that: TS 5.1 playground. This case loses the relevant signatures in (somewhat complicated) |
Yeah, the fallback logic is for unions of arrays over differing element types (to consider them close enough to a single array over the union of both element types) - this example is differing array types over the same element type. We end up saying we can't consider the |
For now, we've chosen to leave this behavior as-is, unless we get some more frequent/compelling examples that require unifying multiple generic signatures to the subtype rather than dropping them, as we do today. |
🔎 Search Terms
overlaod union
🕗 Version & Regression Information
This changed between versions ______ and _______This changed in commit or PR _______I was unable to test this on prior versions because _______⏯ Playground Link
https://www.typescriptlang.org/play/?ts=5.7.0-dev.20240919#code/FAMwrgdgxgLglgewgAgOYCcFgA4CECeAPACoB8AFAIbrqX4BcyAgjXSaQD7IBKAppQBMkAG3wtaRMgBpkAa14NklCPgCUjALKVshZfhni2ZUsgDewZMnS8YYdCmoSAdNYFgovQlp16DrSaSB5FRQUDK8wrwAtrwQMKrIALwm5haWyFBIAM4wcknIMPjYvAggcgpJiYnIAOTg0PBINcgA-Mjk8vhKWe0R0bEwjMQJyUoqquR9MXEJjFMDANqd3eX4pcjEALoA3GmWkbkYWNj5lKFOqDYdqrvpyHBl5ACERzgJ5neWZ1BOWVeyMleJ2qC02Nz2yAAvhCgU5sGAsgALSaRabxW7pay2exKUK7NKQmQQXgAd2Q3l0Kj8EnYFFU4OhwCAA
💻 Code
🙁 Actual behavior
getting the errors:
Expected 0 type arguments, but got 1.
🙂 Expected behavior
Allowing the use of the 3rd overload method
reduce<U>
ofArray
/ReadonlyArray
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: