question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

.every() .find() .filter() methods fail with "This expression is not callable." error on union of array types

See original GitHub issue

Bug 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

💻 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:open
  • Created 2 years ago
  • Reactions:59
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

7reactions
jcalzcommented, Jan 27, 2022

Maybe something could be done specifically for arrays instead of worrying about merging arbitrary signatures? Like, widen A[] | B[] to readonly (A | B)[] for these failing method calls? 🤷‍♂️

4reactions
weswighamcommented, Jun 2, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found