title: How to indicate that path is unreachable in TypeScript
body: <p>I have some TypeScript code that looks essentially like this:</p>
  <pre><code>if( ... ) 
      result = $(document.createElement(&quot;div&quot;)) ;
  } else if( ... ) {
      result = $(document.createElement(&quot;div&quot;)) ;
  } else {
      assert.unreachable( &quot;Unknown label in buildHTML.&quot;) ;
  }
  result.attr( &quot;data-childNumber&quot;, childNumber.toString() ) ; 
  </code></pre>
  <p>The return type of <code>assert.unreachable</code> is <code>never</code>.</p>
  <p>There is an error on the last line:</p>
  <blockquote>
  <p>Variable 'result' is used before being assigned.</p>
  </blockquote>
  <p>It seems to me that the <code>never</code> result from <code>assert.unreachable</code> should tell the compiler that there is no path out of the <code>else</code> part.</p>
  <p>I know that I can suppress the error by adding <code>throw null;</code> at the end of the <code>else</code>, but this seems inelegant.</p>
  <p>A similar problem comes up in the definition of <code>unreachable</code>. It looked like this</p>
  <pre><code>export function unreachable( message? : string ) : never {
      if( message===undefined ) message = &quot;Unreachable code reached.&quot; ;
      else message = &quot;Unreachable code reached: &quot;+message ;
      raiseTheAlarm( message ) ;
  }
  </code></pre>
  <p>where the result type of <code>raiseTheAlarm</code> is <code>never</code>.  In this case, I got an error:</p>
  <blockquote>
  <p>A function returning 'never' cannot have a reachable end point.</p>
  </blockquote>
  <p>I fixed this by adding a <code>return</code> keyword before the call to  <code>raiseTheAlarm</code>.  This looks a bit odd.  (Of course, <code>throw null;</code> after the call would also have worked.)</p>
  <p>Is there a better way to tell the compiler that a point in the code is not reachable?</p>