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: [prefer-nullish-coalescing]ignoreConditionalTests doesn't ignore the boolean! operator in a condition #10284

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
@AndersRobstad

Description

@AndersRobstad

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.6.3&fileType=.ts&code=DYUwLgBAZg9jBcEDOYBOBLAdgcwgHwgFdMATEKLEEiAXggHJYZ6BuAKFEgCMBDVRFBhz4ipcpWp16vVKzZsQADwAOMVJCjEAxmHQxMEMCBQBhHkhAAKAJQQA3mwCQ6KBEtN8BGbYePHW-SQYUAA6YBhsS0Y4CDUIGXprdkcAXzY0hRU1DW1dfUNjMDMLACYbeycXNwBCdxi8Lz5rHyd-QOCQMIiozBgNGLiEpKc0jI86YjIKTCp2GVpRKYl2IA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Y6RAM0WlqYSNkAC1pkA9gEMkyMswDm6MAG1IvaOOiQAuuDABfEPqA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkAhqqrAO4BSZlemArugDTgaMABbpoAa3YUwXXgJpR0JALKwAJtwwBJIniyxE02f0G0AZrEzR0AYWIlkJPbpt0HRAOY6AYmnQA5OnglIx4TBUhMJVhUADd0dmJVDQxQuVMoEnFkRAAZZAAjG1EJNPChElhuK3RlOkNOMPkKrmRoPDLm2iJYAFUiaBLxdDUdNXQADxGAQWhrEg4ZJozIHq0kVDbkPAAldDxq0k6Vnu8GVDxhTCqPYVcSJR0AZWZtweOInv7uB7Vc2GgDEWxi6UC%2BRB%2BIwACnRMEF9lhgctPrB1ohNtBtth4phMMhxh8hPB1Jp0HtKqhuARiNJIAVuEQ1BhMJBQZAcQU6AR4MlSU8AJ66OgTaRmIHoMCCAC%2BIClQA&tokens=false

Repro Code

letfoo:string|undefined='foo';letbar:string|undefined='bar';exportfunctiontestCase(){if(foo||bar){console.log('foo or bar');}}exportfunctiontestCase2(){if(!(foo||bar)){console.log('not foo or bar');}}foo=undefined;bar=undefined;

ESLint Config

module.exports={"rules":{"@typescript-eslint/prefer-nullish-coalescing":["error"]}}

tsconfig

{"compilerOptions": {"allowJs":true,"checkJs":true,"esModuleInterop":true,"forceConsistentCasingInFileNames":true,"resolveJsonModule":true,"skipLibCheck":true,"sourceMap":true,"strict":true,"noUncheckedIndexedAccess":true,"noImplicitReturns":true,"noFallthroughCasesInSwitch":true,"noUnusedLocals":true,"noUnusedParameters":true,"noImplicitOverride":true,"moduleResolution":"bundler","verbatimModuleSyntax":false   }}

Expected Result

I would have expected that the if-statement insidetestCase2 also is allowed, but after updating from8.12.2 to8.13.0 it results in an error suggesting to use?? instead referring to theprefer-nullish-coalescing rule.

I think it should to be allowed to do this check to see whether one of two strings are truthy inside an if-statement as shown intestCase2.

Actual Result

In the example providedtestCase2 willnot run theconsole.log statement whenfoo="" andbar="bar", however, thetestCase1runs the if-statement in the same case. This is due to the difference between|| and?? when it comes to the empty string.

Meaning the rule now suggests something that is logically not the same, and would change the behavior of code similar to the one shown in the example

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


      [8]ページ先頭

      ©2009-2025 Movatter.jp