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

Skip to content

Bug: [no-unnecessary-boolean-literal-compare] doesn't flag values of a type parameter with boolean type constraint #10443

Closed
@ronami

Description

@ronami

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.7.2&fileType=.ts&code=PTAEDMEMEsBsGcBQBjA9gO3gF1FgptgIwBcoAFPKgLZ4DCGAJtFtBqQEaqqx6ToCUoALwA%2BUADdU0BsNCUa9dExYZhYgN6JQoaOHLy6jZq3TChQ3ACcArnkHqAvogcBuRIhByAFqmuwZUHAoGNi4BFgATKQAPAAqoHgAHvhK8KCc3LzoIhTUhkrGbKCxgqISUjIWBorKJmqgmtq6%2Bnk1habmFlg2dg1OrohAA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1tiacTJTIAhtEK0ARhw5IhTWo3yJoQ%2BLTIcAtsRGJ0UJdA7RI4MAF8QZoA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

// fails
const test1: (someCondition: boolean) => void = someCondition => {
  if (someCondition === true) {}
};

// should fail
const test2: <T extends boolean>(someCondition: T) => void = someCondition => {
  if (someCondition === true) {}
};

ESLint Config

module.exports = {
  parser: "@typescript-eslint/parser",
  rules: {
    "@typescript-eslint/no-unnecessary-boolean-literal-compare": "error"
  },
};

tsconfig

{
  "compilerOptions": {
    "strictNullChecks": true
  }
}

Expected Result

I expect all use-cases to be consistent and report as errors.

Actual Result

The use-cases with a type constraint doesn't report as an error (even though it should).

Additional Info

This seems similar to #10311, and it looks like the fix should be similar.

Note that this issue is also similar to #10442, and I wasn't sure if I should create one issue for each rule or aggregate them under a single issue. I apologize if this was a bit spammy. I checked existing rules for similar problems after resolving #10311.

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