Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
Closed
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
declareconstcase1Loading:boolean|undefined|null;declareconstcase2Loading:boolean;constresult=case1Loading||case2Loading;// case2 = false || case2// case1 = true || case2// case2 = undefined || case2// This one is luckily working in this case// case1 = true ?? case2// Above ones are OK, using `||`// But the next one is causing issues with `??`// case1 = false ?? case2// This should be evaluate to `case2` when using with `||`, but it's always `case1` with `??`// Hence change `||` to `??` breaks the logic, so the rule should NOT report
ESLint Config
{"rules":{"@typescript-eslint/prefer-nullish-coalescing":"error"}}
tsconfig
{"compilerOptions": {"strictNullChecks":true }}
Expected Result
The rule should not report againstnullable boolean
, since it will likely break the logic
Actual Result
Prefer using nullish coalescing operator (??
) instead of a logical or (||
), as it is a safer operator. 11:29 - 11:31
Fix to nullish coalescing operator (
??
).
Additional Info
Another solution is to add anignoreNullableBoolean
option, since it will likely breaks the logicbreak