Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Bug: [no-unnecessary-boolean-literal-compare] should requirestrictNullChecks #10706

Closed
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
@earshinov

Description

@earshinov

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 havesearched for related issues and found none that matched my issue.
  • I haveread the FAQ and my problem is not listed.

Playground Link

https://typescript-eslint.io/play/#ts=5.7.3&fileType=.ts&code=GYVwdgxgLglg9mABFApgZygCgIYH4BciARnHADYrZgCUhJ5lSA3gLABQiiATilCF0myIAhAF5RiYNjJoUAbnYBfdu1QZM1OUA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1tiacTJTIAhtEK0ARhw5IhTWo3yJoQ%2BLTIcAtsRGJ0UJdA7RI4MAF8QZoA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eFYAZgIaonrhgC%2BIfkA&tokens=false

Repro Code

functiontest(a?:boolean):boolean{returna!==false;}test();

ESLint Config

{"rules":{"@typescript-eslint/no-unnecessary-boolean-literal-compare":"error"}}

tsconfig

{"compilerOptions": {"strict":false  }}

Actual Result

With the configuration above (withoutstrictNullChecks), the@typescript-eslint/no-unnecessary-boolean-literal-compare rule emits a (false) error. Applying the automatic fix translates

functiontest(a?:boolean):boolean{returna!==false;}

into

functiontest(a?:boolean):boolean{returna;}

which is obviously not equivalent asa is nullable.

Root cause seems to be that withoutstrictNullChecks, TypeScript reports the type ofa asboolean instead ofboolean | undefined, making typescript-eslint think thata is not nullable ⇒a !== false is equivalent to justa.

My guess is that theno-unnecessary-boolean-literal-compare rule absolutely has to check forstrictNullChecks and refuse to work (like other rules do, such asprefer-nullish-coalescing).

We already broke our app in runtime after applyingeslint --fix without reviewing each and every change. We can't enablestrict /strictNullChecks as it would emit thousands of errors in the legacy codebase.

Expected Result

Either of
a. (best option) no error, like withstrictNullChecks: true (I assume, not technically possible)
b. eslint refuses to work if theno-unnecessary-boolean-literal-compare rule is enabled, butstrictNullChecks aren't

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

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp