Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
Description
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
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, thetestCase1
runs 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