-
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
.map() .reduce() .filter() methods fail with "This expression is not callable." error on valid array with union type #36390
Comments
I think this is a duplicate of #7294 |
Duplicate of #7294 (see comment). Related to #29011. Mentioned in documentation as caveats for improved behavior for calling union types:
|
Is this really a duplicate? The 'duplicate' issue is marked as closed, but this issue still exists. If it really is a duplicate, can we re-open #7294 to handle this case? |
The reason stated by @weswigham for not unifying for generic signatures with multiple signatures is that:
But for function signatures originating from the same declaration we can be sure that we are talking about the same overload signatures in the same order and with the same generic parameters. As long as the generics don't have constraints, unifying the signatures should be safe IMO. I think that unifying for this case would satisfy a lot of use cases. |
Yeah, I have a change around here somewhere that allows it for exactly that situation rummages through bin of old PRs |
@weswigham What was wrong with it? Why did it get stuck ? Can we revive it :D ? |
#31023 contains the relevant code. It's a bit old, and some parts of it are probably no longer needed thanks to some other signature resolution changes we made (namely the base signature stuff should no longer be needed). |
Cool! So is this planned for a release in the future I'm guessing? I wanted to have a look at this over the weekend but glad to see it already there and we will get eventually :) |
Looks like my issue #36307 talks about pretty much the same behavior, linking for discoverability. Glad to see there's been some movement! |
Until this gets fix you can do something like:
|
I got similar error while calling map on |
This issue is closed, but the const arr: number[] | string[] = [];
arr.reduce((acc: Array<string>, a: number | string, index: number) => {
return []
}, [])
/* This expression is not callable.
Each member of the union type '...' has signatures,
but none of those signatures are compatible with each other. */ |
I'm super excited about the improvements in #31023! But it doesn't seem to have completely resolved the issues with calling array methods on unions of arrays. I tested a few common array methods and found the following results:
I've created a new issue to track the remaining functionality. |
is this getting fixed anytime soon ? |
@ialexryan What typescript version does this fix go out? |
We're on the latest Typescript and bumped into this. Do you know when it's going out? @RyanCavanaugh |
I just bumped into the same issue |
How is this issue closed? |
I think #44373 is the open issue about this |
Thanks, didn't see that.. :) |
I just bumped into the same issue too |
TypeScript Version: any
Code:
Expected behavior: TS should let me iterate through array (I tell it the type is either array of numbers OR array of strings (not an array of mixed types). In any case the variable is an array and those methods should be callable.
Actual behavior: TS throws error "This expression is not callable."
The text was updated successfully, but these errors were encountered: