Skip to content

Bug: [switch-exhaustiveness-check] - case of relying on an third party enums that are only imported as types #11842

@salisbury-espinosa

Description

@salisbury-espinosa

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Playground Link

I couldn't attach a playground link because I needed two code source files for the case (to import one from the other) - only one is created in the sandbox...

Related links

issue
PR
doc

Repro Code

enum.ts

export enum DATA_TYPE {
  First = 0,
  Second = 1,
}

index.ts

import type { DATA_TYPE } from './enums';

export function test(type: DATA_TYPE) {
  switch (type) {
      case 0: { throw new Error('Not implemented yet: 0 case') }
      case 1: { throw new Error('Not implemented yet: 1 case') }
      default:
  }
}

ESLint Config

const {
    defineConfig,
} = require("eslint/config");

const tsParser = require("@typescript-eslint/parser");
const typescriptEslintEslintPlugin = require("@typescript-eslint/eslint-plugin");

module.exports = defineConfig([{
    languageOptions: {
        parser: tsParser,

        parserOptions: {
            project: "./tsconfig.json",
        },
    },

    plugins: {
        "@typescript-eslint": typescriptEslintEslintPlugin,
    },

    files: ["**/*.ts"],

    "rules": {
        "@typescript-eslint/no-unsafe-enum-comparison": "off",
        "@typescript-eslint/switch-exhaustiveness-check": ["error"],
    },
}]);

tsconfig

{
  "include": ["*.ts"],
  "compilerOptions": {
    "strictNullChecks": true
  }
}

Expected Result

success

Actual Result

  4:11  error  Switch is not exhaustive. Cases not matched: DATA_TYPE.First | DATA_TYPE.Second  @typescript-eslint/switch-exhaustiveness-check

✖ 1 problem (1 error, 0 warnings)

Additional Info

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-pluginworking as intendedIssues that are closed as they are working as intended

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions