.every() .find() .filter() methods fail with "This expression is not callable." error on union of array types
See original GitHub issueBug Report
🔎 Search Terms
- This expression is not callable
- none of those signatures are compatible with each other
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about union types. I also reviewed previous related issues.
⏯ Playground Link
- .every() does not work
- .filter() does not work
- .find() does not work
- .reduce() also doesn’t work, but there is already an issue for that one. (Perhaps we should merge it into this?)
💻 Code
interface Fizz {
id: number;
fizz: string;
}
interface Buzz {
id: number;
buzz: string;
}
([] as Fizz[] | Buzz[]).filter(item => item.id < 5);
🙁 Actual behavior
Compilation fails with the following error:
This expression is not callable.
Each member of the union type '{ <S extends Fizz>(predicate: (value: Fizz, index: number, array: Fizz[]) => value is S, thisArg?: any): S[]; (predicate: (value: Fizz, index: number, array: Fizz[]) => unknown, thisArg?: any): Fizz[]; } | { ...; }' has signatures, but none of those signatures are compatible with each other.
🙂 Expected behavior
Compilation succeeds, as it does for map and several other array functions.
🔖 Useful links
Issue Analytics
- State:
- Created 2 years ago
- Reactions:59
- Comments:11 (5 by maintainers)
Top Results From Across the Web
typescript, Array.prototype.map() has error 'expression is not ...
map() has error 'expression is not callable' when the callee array is union with empty array. Save this question. Show activity on this...
Read more >The starting point for learning TypeScript
Find TypeScript starter projects: from Angular to React or Node.js and CLIs. ... Get Started. Quick introductions based on your background or preference....
Read more >What's New In Python 3.10 — Python 3.11.1 documentation
Notice this won't work if PyErr_Display() is not called to display the error which can happen if some other custom error display function...
Read more >TypeScript Fundamentals - Joy of Code
The pokemon array contains only strings, so we get a type error when ... Another tip I have is to include console.clear() at...
Read more >API Reference — pydash 5.1.2 documentation
This method is similar to union() except that it accepts iteratee which is invoked for each element of each arrays to generate the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Maybe something could be done specifically for arrays instead of worrying about merging arbitrary signatures? Like, widen
A[] | B[]
toreadonly (A | B)[]
for these failing method calls? 🤷♂️Well, we’d need to come up with sensible rules for merging overload lists. Conceptually, we could (attempt to) make a list of 4 overloads by combining each of the input signatures, except there’s no inherent ordering to those 4 signatures, unlike a normal overload set, so it’s unclear how we’d choose which signature to resolve against, ultimately.