title: How to use filter in TypeScript on different array types
body: <p>Given is the function signature below:</p>
  <pre><code>function foo(): string[] | number[]
  </code></pre>
  <p>Why does TS complain about the follow function call of filter?</p>
  <pre><code>foo().filter((v) =&gt; true);
        ^^^^^^
        Error
  </code></pre>
  <blockquote>
  <p>This expression is not callable.
  Each member of the union type '{ (predicate: (value: number, index: number, array: number[]) =&gt; value is S, thisArg?: any): S[]; (predicate: (value: number, index: number, array: number[]) =&gt; unknown, thisArg?: any): number[]; } | { ...; }' has signatures, but none of those signatures are compatible with each other.</p>
  </blockquote>
  <p>Of course I can cast it to <code>[]</code>, but what is the proper way here? The error message is very difficult to understand? How would one decipher this?</p>
  <p>Example: <a href="https://www.typescriptlang.org/play?ssl=1&amp;ssc=1&amp;pln=6&amp;pc=27#code/GYVwdgxgLglg9mABMOcAUBKAXIsIC2ARgKYBOA2gLqIA+iAzlKTGAOZWIDeAUIn4qWJQQpJFQDc3AL7dZKdBgB0wGABsoZNGgBuGRAF4AfIiYhiGcUA" rel="nofollow noreferrer">Playground</a></p>