Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
4 tasks done
jtbandes opened this issue Oct 29, 2024 · 5 comments · Fixed by #10232
Closed
4 tasks done

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

jtbandes opened this issue Oct 29, 2024 · 5 comments · Fixed by #10232
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@jtbandes
Copy link
Contributor

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

@jtbandes jtbandes added bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Oct 29, 2024
@kirkwaiblinger kirkwaiblinger added accepting prs Go ahead, send a pull request that resolves this issue and removed triage Waiting for team members to take a look labels Oct 29, 2024
@bradzacher
Copy link
Member

The new rule options had an incorrect default and has been fixed in #10223 and has been released in 8.12.2

@jtbandes
Copy link
Contributor Author

jtbandes commented Oct 29, 2024

I experienced this bug with 8.12.2 (also repro'd with 8.12.2 in the playground). The issue is that it complains a case for undefined is missing even though it is present.

@bradzacher
Copy link
Member

Ah wait my playground hadn't updated to 8.12 sorry. It repros now that I've cleared the cache.

@notaphplover

This comment was marked as off-topic.

@kirkwaiblinger

This comment was marked as off-topic.

@github-actions github-actions bot added the locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. label Nov 12, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
4 participants