title: Undefined not propagating as possible function return type, void works
body: <p>In a shared DB library written by a long-departed senior dev we have two helper functions</p>
  <pre class="lang-js prettyprint-override"><code>/** Helper function to return *exactly* one result. */
  export declare const one: &lt;T&gt;(a: T[]) =&gt; T;
  /** Helper function to return zero or one result. */
  export declare const first: &lt;T&gt;(a: T[]) =&gt; T | undefined;
  </code></pre>
  <p>The former works fine, but the <code>undefined</code> part of the union in the latter doesn't seem to work, instead being ignored by the type-checker when compiling. When we replace it with <code>void</code>, we see expected errors where there has been an assumption that it will return <code>&lt;T&gt;</code>.</p>
  <p>I understand that there is a difference between <code>undefined</code> and <code>void</code> based on <a href="https://stackoverflow.com/questions/58885485/why-does-typescript-have-both-void-and-undefined">Why does TypeScript have both `void` and `undefined`?</a>, since the function also throws errors when you replace the <code>undefined</code> with basically any other type, but <code>undefined</code> seems to be uniquely ignored.</p>
  <p>This <a href="https://www.typescriptlang.org/play?jsx=0#code/PTBiFcDsGMBcEsD2kDOACWiMFMWwFwBQ0yeay2aAvGgDwAqAfABQCG+a9A2gLoCUHetUZpWXAAw9ipWGgBm8AE5kaDFu068BnNAB80UACbYFkbIeGiJUwiHq5Y01LNaLFrAJ4B5OQGVYivCQAOYoHHiBIbzUaFwA5AAW2AA2yYhxADRocQDuiIrJhpnZcojpWXEARq5xUiTOOHgAaqzJXmYxFGxunj7+kaF8TmSwDi3JoEoq8lOw3e7efgFBg4SEydiyESvj4NjhyyFohNshu5Q0o82t7ZR2CfDoKAmI4IVolZSs0NDYAA6jQxZHLYOIAN0opUUvws8FkmFEP3+LjQYNaexOh2C5xiV1g40mylkIE4DyeLzeFmwbnyWUq4Fkj0gcVk1MU+RWaCCaAAth40Ip-lgcklIFzGeh4Dy-vlAUA" rel="nofollow noreferrer">playground</a> shows the error, but I'm not seeing the error when the module is imported in my repo. Under what circumstances would the TS compiler ignore an <code>undefined</code> value in a union function return type?</p>