title: How to compare Enums in TypeScript
body: <p>In TypeScript, I want to compare two variables containing enum values. Here's my minimal code example:</p>
  <pre><code>enum E {
    A,
    B
  }
  
  let e1: E = E.A
  let e2: E = E.B
  
  if (e1 === e2) {
    console.log(&quot;equal&quot;)
  }
  </code></pre>
  <p>When compiling with <code>tsc</code> (v 2.0.3) I get the following error:</p>
  <blockquote>
  <p>TS2365: Operator '===' cannot be applied to types 'E.A' and 'E.B'.</p>
  </blockquote>
  <p>Same with <code>==</code>, <code>!==</code> and <code>!=</code>.
  I tried adding the <code>const</code> keyword but that seems to have no effect.
  The <a href="https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#4.19.3" rel="noreferrer">TypeScript spec</a> says the following:</p>
  <blockquote>
  <p><strong>4.19.3 The &lt;, &gt;, &lt;=, &gt;=, ==, !=, ===, and !== operators</strong></p>
  <p>These operators require one or both of the operand types to be assignable to the other. The result is always of the Boolean primitive type.</p>
  </blockquote>
  <p>Which (I think) explains the error. But how can I get round it?</p>
  <p><strong>Side note</strong><br />
  I'm using the Atom editor with <a href="https://atom.io/packages/atom-typescript" rel="noreferrer">atom-typescript</a>, and I don't get any errors/warnings in my editor. But when I run <code>tsc</code> in the same directory I get the error above. I thought they were supposed to use the same <code>tsconfig.json</code> file, but apparently that's not the case.</p>