<p dir="auto">Hi,</p>
<p dir="auto">We have been adding compile time safety to the magic string problem through the excellent string literal type introduced in 1.8.</p>
<p dir="auto">One case that we are finding slipping through the safety net is the following:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="type Foo = 'a' | 'b';

const foo: Foo = 'a';

if (foo === 'bar') {
}"><pre class="notranslate"><span class="pl-k">type</span> <span class="pl-smi">Foo</span> <span class="pl-c1">=</span> <span class="pl-s">'a'</span> <span class="pl-c1">|</span> <span class="pl-s">'b'</span><span class="pl-kos">;</span>

<span class="pl-k">const</span> <span class="pl-s1">foo</span>: <span class="pl-smi">Foo</span> <span class="pl-c1">=</span> <span class="pl-s">'a'</span><span class="pl-kos">;</span>

<span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">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-kos">}</span></pre></div>
<p dir="auto">Here the <code class="notranslate">Foo</code> type is being compared to an incompatible value 'bar'.</p>
<p dir="auto">It would be nice to get an error here similar to an enum comparison error:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="enum Foo { a, b }
enum Bar { a, b }
let foo: Foo;

if (foo === Bar.a) { // Operator '===' cannot be applied to types 'Foo' and 'Bar'
}
"><pre class="notranslate"><span class="pl-k">enum</span> <span class="pl-smi">Foo</span> <span class="pl-kos">{</span> <span class="pl-c1">a</span><span class="pl-kos">,</span> <span class="pl-c1">b</span> <span class="pl-kos">}</span>
<span class="pl-k">enum</span> <span class="pl-smi">Bar</span> <span class="pl-kos">{</span> <span class="pl-c1">a</span><span class="pl-kos">,</span> <span class="pl-c1">b</span> <span class="pl-kos">}</span>
<span class="pl-k">let</span> <span class="pl-s1">foo</span>: <span class="pl-smi">Foo</span><span class="pl-kos">;</span>

<span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">foo</span> <span class="pl-c1">===</span> <span class="pl-smi">Bar</span><span class="pl-kos">.</span><span class="pl-c1">a</span><span class="pl-kos">)</span> <span class="pl-kos">{</span> <span class="pl-c">// Operator '===' cannot be applied to types 'Foo' and 'Bar'</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">This is especially useful for obtaining a compile time error when the original strings <code class="notranslate">('a' | 'b')</code> are refactored during the course of development.</p>
<p dir="auto">I'm aware that there are workarounds involving pseudo string enums, but this is a suggestion for this primitive case.</p>
<p dir="auto">Thanks.</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>