title: How to map over possibly empty array in Typescript
body: <p>I have a function whose parameter can either be an empty array or an array with strings.</p>
  
  <p>So I handle this with a union type of  <code>[] | string[]</code></p>
  
  <p>Then, Inside the function, I check to see if the array.length > 0, and if it IS, then I map over the parameter.</p>
  
  <pre><code>type Kennel = [] | string[]
  
  const petDogs = (kennel: Kennel)  =&gt; {
    if (kennel.length &gt; 0){
      return kennel.map((name:string)=&gt;name)
    } else {
      return "no doggies to pet"
    }
  }
  </code></pre>
  
  <p>However, on compilation, I get the error </p>
  
  <p><code>Cannot invoke an expression whose type lacks a call signature. Type '(&lt;U&gt;(callbackfn: (value: never, index: number, array: never[]) =&gt; U, thisArg?: any) =&gt; U[]) | (&lt;U&gt;(callbackfn: (value: string, index: number, array: string[]) =&gt; U, thisArg?: any) =&gt; U[])' has no compatible call signatures</code></p>
  
  <p>I have tried using function overloading, but it didn't solve the compilation error.</p>
  
  <p>example:</p>
  
  <pre><code>interface PetDogs {
    (kennel: []): string;
    (kennel: string[]): string[];
  }
  </code></pre>