<p dir="auto">Here is a simple example:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="function f(s: &quot;foo&quot; | &quot;bar&quot;) {
  if (s == &quot;baz&quot;) {
    ...
  }
}"><pre class="notranslate"><span class="pl-k">function</span> <span class="pl-en">f</span><span class="pl-kos">(</span><span class="pl-s1">s</span>: <span class="pl-s">"foo"</span> <span class="pl-c1">|</span> <span class="pl-s">"bar"</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">s</span> <span class="pl-c1">==</span> <span class="pl-s">"baz"</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    ...
  <span class="pl-kos">}</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">As you see, there is a typo in "baz", but tsc doesn't catch that. On the other hand, if you try to <code class="notranslate">s == 123</code>, tsc will say that a string cannot be compared with a number.</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="type foo = 'hey' | 'nay';

switch (&lt;foo&gt;undefined) {
    case 'boom': console.log('never the case'); break; // expected unreachable code, actual no problem
}"><pre class="notranslate"><span class="pl-k">type</span> <span class="pl-smi">foo</span> <span class="pl-c1">=</span> <span class="pl-s">'hey'</span> <span class="pl-c1">|</span> <span class="pl-s">'nay'</span><span class="pl-kos">;</span>

<span class="pl-k">switch</span> <span class="pl-kos">(</span><span class="pl-kos">&lt;</span><span class="pl-smi">foo</span><span class="pl-kos">&gt;</span><span class="pl-c1">undefined</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-k">case</span> <span class="pl-s">'boom'</span>: <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s">'never the case'</span><span class="pl-kos">)</span><span class="pl-kos">;</span> <span class="pl-k">break</span><span class="pl-kos">;</span> <span class="pl-c">// expected unreachable code, actual no problem</span>
<span class="pl-kos">}</span></pre></div>