Skip to main content


Disallow comparing an enum value with a non-enum value.


Extending "plugin:@typescript-eslint/strict" in an ESLint configuration enables this rule.


This rule requires type information to run.

The TypeScript compiler can be surprisingly lenient when working with enums. For example, it will allow you to compare enum values against numbers even though they might not have any type overlap:

enum Fruit {

declare let fruit: Fruit;

fruit === 999; // No error

This rule flags when an enum typed value is compared to a non-enum number.

enum Fruit {

declare let fruit: Fruit;

fruit === 999;
enum Vegetable {
Asparagus = 'asparagus',

declare let vegetable: Vegetable;

vegetable === 'asparagus';
module.exports = {
"rules": {
"@typescript-eslint/no-unsafe-enum-comparison": "error"
Try this rule in the playground ↗

When Not to Use It

If you don't mind number and/or literal string constants being compared against enums, you likely don't need this rule.


This rule is not configurable.