title: This expression is not callable. Each member of the union type has signatures, but none of those signatures are compatible with each other
body: <p>I'm getting this error on the .map function with the following code:</p>
  
  <blockquote>
    <p>This expression is not callable.
      Each member of the union type '((callbackfn: (value: number, index: number, array: number[]) => U, thisArg?: any) => U[]) | ((callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[])' has signatures, but none of those signatures are compatible with each other.</p>
  </blockquote>
  
  <pre><code>type ResponseTypeA = {
    data: number[];
  }
  
  type ResponseTypeB = {
    data: string[];
  }
  
  const response: ResponseTypeA | ResponseTypeB = {
    data: []
  };
  
  const data = response.data.map(t =&gt; {
    if (typeof t === 'number') return String(t);
    return t;
  });
  </code></pre>
  
  <p>Any ideas on how to resolve this without using <code>any</code>?</p>
  
  <p>Edit:</p>
  
  <p>Here is a solution I found:</p>
  
  <pre><code>type ArrayElem&lt;A&gt; = A extends Array&lt;infer Elem&gt; ? Elem : never
  
  export function elemT&lt;T&gt;(array: T): Array&lt;ArrayElem&lt;T&gt;&gt; {
    return array as any
  }
  
  type ResponseTypeA = {
    data: number[];
  }
  
  type ResponseTypeB = {
    data: string[];
  }
  
  const response: ResponseTypeA | ResponseTypeB = {
    data: []
  };
  
  const data = elemT(response.data).map(t =&gt; {
    if (typeof t === 'number') return String(t);
    return t;
  });
  </code></pre>