How to compare Enums in TypeScript
In TypeScript, I want to compare two variables containing enum values. Here's my minimal code example: enum E { A, B } let e1: E = E.A let e2: E = E.B if (e1 === e2) { console.log("equal") } When compiling with tsc (v 2.0.3) I get the following error: TS2365: Operator '===' cannot be applied to types 'E.A' and 'E.B'. Same with == , !== and != . I tried adding the const keyword but that seems to have no effect. The TypeScript spec says the following: 4.19.3 The <, >, <=, >=, ==, !=, ===, and !== operators These operators require one or both of the operand types to be assignable to the other.