10000 Bug: [no-unsafe-enum-comparison] false positive with enums in a union with branded types · Issue #7114 · typescript-eslint/typescript-eslint · GitHub
[go: up one dir, main page]

Skip to content

Bug: [no-unsafe-enum-comparison] false positive with enums in a union with branded types #7114

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
bradzacher opened this issue Jun 18, 2023 · 2 comments · Fixed by #9777
Closed
4 tasks done
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

@bradzacher
Copy link
Member

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.0.3&sourceType=module&showAST=es&code=KYOwrgtgBAYg9nKBvAsAKClAglAvFAcgEMCAadAX3XQBcBPAB2CgCEiAnPKACgGcb2ASxABzKADJkUAPrSARuyIgAJgC4oYEAGsQcAO4goFAJRQAPrAQBuammXAAxgBsOzB3BD8ocjurbsbNHRBADMeH05cKMI5AlNUDCgAeiTKdCA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1tieQEMAZonpNYAW1pkOY4nyrIOTdFETRoHaJHBgAviB1A&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA

Repro Code

enum Foo {
  A = 'a',
}

type Bar = (string & { __brand: unknown }) | Foo;

declare const bar: Bar;

if (bar === 'b') {
  //
}

ESLint Config

module.exports = {
  parser: "@typescript-eslint/parser",
  rules: {
    "@typescript-eslint/no-unsafe-enum-comparison": ["error"],
  },
};

tsconfig

No response

Expected Result

No error

Actual Result

The rule errors on the comparison because it doesn't recognise the branded type as the base type

Additional Info

No response

@bradzacher bradzacher 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 accepting prs Go ahead, send a pull request that resolves this issue and removed triage Waiting for team members to take a look labels Jun 18, 2023
@bradzacher bradzacher mentioned this issue Jun 18, 2023
< 8000 div class="flex-auto wb-break-word" id="ref-pullrequest-1761354723" > feat(eslint-plugin): apply final v6 changes to configs #7110
Merged
3 tasks
@Zamiell
Copy link
Contributor
Zamiell commented Sep 15, 2023

I'll try working on this once #7541 is approved.

@Zamiell
Copy link
Contributor
Zamiell commented Sep 18, 2023

I figured this one out this morning. The fix is to add this:

Edit - This ended up being wrong. The correct fix is included in PR #9777.

@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 Aug 27, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 27, 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
2 participants
0