title: How do I assign a value to a conditional type?
body: <p>I'm trying to write a function such that the first parameter is <code>boolean</code>, and depending on whether this argument is <code>true</code> or <code>false</code>, the second argument is a function that accepts either a <code>string</code> or <code>string[]</code>.</p>
  <p>Here is my attempt:</p>
  <pre class="lang-js prettyprint-override"><code>type P&lt;B extends boolean&gt; = B extends true ? string[] : string
  
  function callback&lt;B extends boolean&gt;(b: B, t: (f: P&lt;B&gt;) =&gt; void) {
      const file = 'file'
      if (b) {
          t([file]) // &lt;-- Error: Argument of type 'string' is not assignable to parameter of type 'P&lt;B&gt;'.
      } else {
          t(file)   // &lt;-- Error: Argument of type 'string[]' is not assignable to parameter of type 'P&lt;B&gt;'.
      }
      
  }
  
  callback(false, (f: string) =&gt; {})  // &lt;-- No problem, resolves the correct argument type
  callback(true, (f: string[]) =&gt; {}) // &lt;-- No problem, resolves the correct argument type
  </code></pre>
  <p>This works for resolving the correct argument types when the function is called. However, inside the function, the TS compiler is giving me an error that it cannot resolve the conditional type to either <code>string</code> or <code>string[]</code>. What is the correct way to do this?</p>
  <p><a href="https://www.typescriptlang.org/play?#code/C4TwDgpgBACgPAIShAHsCA7AJgZygIwHtCAbCAQwwD4oBeKJVdbPYAJwFdoB+KHdgJYYA5gG0AulABcfQSICwAKCUAzDhgDGwAYQxQN5EiXzkNAa0TI0mXAWJlKVABT4ZCADRRgMpypnwEKgBKOhoAN0IBLBCAbyUoBP1dfigVATI6KAByNLIs+MSBFSgXWILExOAnUVyIcSDyqABfZBIcaDjFCoqq2oauxKbGpSHlRQMjE3NfQ3bPXxl+NiFhENoaGKagoA" rel="nofollow noreferrer">Playground link</a>.</p>