title: Simple function with conditional type
body: <p>The following function was largely lifted from the <a href="https://www.typescriptlang.org/docs/handbook/advanced-types.html#conditional-types" rel="noreferrer">typescript handbook section on using <em>conditional types</em></a>, yet it doesn't work:</p>
  
  <pre><code>function test&lt;T extends boolean&gt;(a: T): T extends true ? string : number {
    return a ? '1' : 1
  }
  </code></pre>
  
  <p>Typescript is reporting that:</p>
  
  <pre><code>Type '1 | "1"' is not assignable to type 'T extends true ? string : number'.
    Type '1' is not assignable to type 'T extends true ? string : number'.
  </code></pre>
  
  <p>I imagine I'm missing something obvious. How can I construct this function so that typescript correctly infers the type based on the function's argument?</p>
  
  <p>I realize that this specific problem could be solved using function signature overloading, but I'd like to learn more about conditional types.</p>