title: Overloading function types
body: <h3>Problem</h3>
  
  <p>I have this type definition:</p>
  
  <pre><code>export type StringOrErrorCallback = (error: ?Error, result: string) =&gt; void;
  </code></pre>
  
  <p><code>error</code> is obviously nullable.</p>
  
  <p>However, I want <code>result</code> to exist only when <code>error</code> is not truthy.</p>
  
  <p>If I do this:</p>
  
  <pre><code>export type StringOrErrorCallback = (error: ?Error, result?: string) =&gt; void;
  </code></pre>
  
  <p>I make <code>result</code> optional, so it's all fine for the caller of this function, but the users will need to check not only the <code>error</code> argument, but also the <code>result</code> argument.</p>
  
  <h3>Examples</h3>
  
  <pre><code>//user
  function doSomething(error, result) {
    if (error) {
      return console.error(error);
    }
    // it's a given that "result" exists at this point
  }
  
  //caller (both lines should be valid)
  doSomething(new Error('something happened'));
  doSomething(null, 'resulting string');
  </code></pre>