> For AI agents: the complete documentation index is available at https://rslint.rs/llms.txt, the full documentation bundle is available at https://rslint.rs/llms-full.txt.

# no-unsafe-enum-comparison

[Added in v0.1.4](https://github.com/web-infra-dev/rslint/releases/tag/v0.1.4)
## Configuration

| Preset                              | Configured Value |
| ----------------------------------- | ---------------- |
| ✅ ts.configs.recommendedTypeChecked | `"error"`        |
| ✅ ts.configs.strictTypeChecked      | `"error"`        |


```ts title=rslint.config.ts
import { defineConfig, ts } from '@rslint/core';

export default defineConfig([
  ts.configs.recommended,
  {
    rules: {
      '@typescript-eslint/no-unsafe-enum-comparison': 'error',
    },
  },
]);
```

## Rule Details

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

TypeScript enums are a special type that represent a set of named constants. Comparing enum values against raw literals or values of a different enum type is often a mistake and can lead to subtle bugs, since enums in TypeScript have their own type identity.

Examples of **incorrect** code for this rule:

```typescript
enum Fruit {
  Apple,
  Banana,
}

declare const fruit: Fruit;
fruit === 0;
fruit === 'Apple';

enum Vegetable {
  Carrot,
}
fruit === Vegetable.Carrot;
```

Examples of **correct** code for this rule:

```typescript
enum Fruit {
  Apple,
  Banana,
}

declare const fruit: Fruit;
fruit === Fruit.Apple;
fruit === Fruit.Banana;
```

## Original Documentation

- [typescript-eslint: no-unsafe-enum-comparison](https://typescript-eslint.io/rules/no-unsafe-enum-comparison)
- [Source code](https://github.com/typescript-eslint/typescript-eslint/blob/v8.68.0/packages/eslint-plugin/src/rules/no-unsafe-enum-comparison.ts)
