title: TypeScript conditional return value type?
body: <pre class="lang-js prettyprint-override"><code>function f(x:boolean|string) { return x }
  f(true) // boolean | string
  </code></pre>
  <p>Why can't typescript understand that the return value is a boolean?</p>
  <pre class="lang-js prettyprint-override"><code>function f(x:boolean|string) {
      return typeof x === 'boolean' ? true : 'str'
  }
  f(true) // boolean | string
  </code></pre>
  <p>It can't understand this either.</p>
  <p>Do I need to manually setup a function overload definition?</p>