title: Typescript conditional types based on package
body: <p>I'm currently writing a Typescript npm package with optional dependencies. Some of the types are only in effect if a package is installed and can be used.</p>
  <pre class="lang-js prettyprint-override"><code>type baseType = &quot;foo&quot; | &quot;bar&quot;;
  
  type additionalType = test | &quot;baz&quot;;
  </code></pre>
  <p>&quot;baz&quot; only being possible if package xyz exists. So ideally I would be able to have the type adjust to if a package exists.</p>
  <pre class="lang-js prettyprint-override"><code>function doThing(): require(&quot;xyz&quot;) ? additionalTypes : baseType{
  }
  </code></pre>
  <p>All that I have found for conditional typing uses extends which doesn't work when it's not based on user input but rather a third-party dependency.</p>