title: Why does TypeScript have both `void` and `undefined`?
body: <p>In TypeScript, you can annotate a function as returning <code>void</code>:</p>
  
  <pre><code>function fn1(): void {
    // OK
  }
  
  function fn2(): void {
    // Error
    return 3;
  }
  </code></pre>
  
  <p>You can also annotate a function to return <code>undefined</code>:</p>
  
  <pre><code>function fn3(): undefined {
    // OK
    return;
  }
  
  function fn4(): undefined {
    // Error
    return 3;
  }
  </code></pre>
  
  <p>So it seems that if you call a function returning <code>void</code>, you'll always get back the value <code>undefined</code>. Yet you can't write this code:</p>
  
  <pre><code>function fn5(): void {
  }
  let u: undefined = fn5(); // Error
  </code></pre>
  
  <p>Why isn't <code>void</code> just an alias for <code>undefined</code>? Does it need to exist at all?</p>