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 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
Repro Code
let foo: string | undefined = 'foo';
let bar: string | undefined = 'bar';
export function testCase() {
if (foo || bar) {
console.log('foo or bar');
}
}
export function testCase2() {
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
Expected Result
I would have expected that the if-statement inside testCase2
also is allowed, but after updating from 8.12.2
to 8.13.0
it results in an error suggesting to use ??
instead referring to the prefer-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 in testCase2
.
Actual Result
In the example provided testCase2
will not run the console.log
statement when foo=""
and bar="bar"
, however, the testCase1
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