title: flowtype: how can i overload function return types by argument count/types?
body: <p>i want to define an overloaded function like</p>
  
  <pre><code>function first(n?: number) {
    if (number === undefined) {
      // returns a single Item
      return items[0];
    }
  
    // returns an array of Item
    return items.slice(0, n);
  }
  </code></pre>
  
  <p>so that these statements type check:</p>
  
  <pre><code>const item: Item = first(); // no args, so return type is Item
  const items: Array&lt;Item&gt; = first(5); // number arg, so return type is Array&lt;Item&gt;
  </code></pre>
  
  <p>flow knows that the first call to <code>first</code> is going to result in <code>n === undefined</code> (since it would complain if <code>undefined</code> wasn't valid for <code>n</code>) and it understands that it will then take the if branch, so i would think it could infer the return type is <code>Item</code>, but everything i've tried either lets anything pass or always fails.</p>
  
  <p>any idea if this is possible? thanks in advance internet.</p>