Skip to content

Bug: [switch-exhaustiveness-check] False positive with noUncheckedIndexedAccess #10228

Closed
@jtbandes

Description

@jtbandes

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

https://typescript-eslint.io/play/#ts=5.4.5&fileType=.tsx&code=GYVwdgxgLglg9mABMOcAUAPAXIgzlAJxjAHMBtAXQEpEBvAKESbwHcYoIALRTMgBmp1GzJhACGuAKaIARJxgyswkUwBGBSWIDWAbmXNxUxOAAmk4MUkmlKxGeBiQAGyg3biKJwJwWiMJN8AUQJvAjQAAwBVfwwAB0loK0QANzEnEEkcABJaDH4KAF9wqj0RAvoCoA&eslintrc=N4KABGBEAOCGBOBnApvSAuKABALgT2mUQGN4BLaHAWiIBsyA7HAejiVUgBpwp4BXWkQxhQECJFwEipCtTqMWiAO5kcxABY0AHuth9EOMgDdkDIoiobkxANbDIqeAHs0PAL4g3QA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eFYDArugDTg2RGwAqkWgALdNADW6ACYBJIjPQAPWQEFo0dCTKUO6XgF8QhoA&tokens=false

Repro Code

function foo(x: string[]) {
    switch (x[0]) {
      case "hi":
        break;
      case undefined:
      default:
        throw new Error(`Unexpected value: ${x[0]}`);
    }
}

ESLint Config

module.exports = {
  "parser": "@typescript-eslint/parser",
  "rules": {
    "@typescript-eslint/switch-exhaustiveness-check": "error"
  }
};

tsconfig

{
  "compilerOptions": {
    "strict": true,
    "noUncheckedIndexedAccess": true
  }
}

Expected Result

No error

Actual Result

"Switch is not exhaustive. Cases not matched: undefined" — even though case undefined: is present

Additional Info

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issuebugSomething isn't workinglocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.package: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions