title: Typescript return type depending on parameter
body: <p>I am trying to write a function which takes a parameter of type boolean and returns one of two types, depending on the value of the input. I have found two approaches:</p>
  
  <pre><code>function dependsOnParameter&lt;B extends boolean&gt;(x: B): B extends true ? number : string {
      if (x) {
          return 3;
      } else {
          return "string";
      }
  }
  </code></pre>
  
  <p>Here, TypeScript says that <code>Type '3'/'"string"' is not assignable to type 'B extends true ? number : string'.</code></p>
  
  <p>My other approach looks like this:</p>
  
  <pre><code>function dependsOnParameter(x: true): number;
  function dependsOnParameter(x: false): string;
  function dependsOnParameter(x: boolean): number | string {
      if (x) {
          return 3;
      } else {
          return "string";
      }
  }
  </code></pre>
  
  <p>This compiles; however, if I try to use my function:</p>
  
  <pre><code>function calling(x: boolean) {
      dependsOnParameter(x);
  }
  </code></pre>
  
  <p>I get <code>Argument of type 'boolean' is not assignable to parameter of type 'false'</code>.</p>
  
  <p>Is there any way to achieve what I want without using <code>any</code>?</p>