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
interfaceBox{value:string;}declarefunctiongetFallbackBox():Box;declareconstdefaultBox:{a:{b:Box|undefined}};declareconstdefaultBoxOptional:{a?:{b?:Box|undefined}};// reports correctlydefaultBox.a.b!=null ?defaultBox.a.b :getFallbackBox();// should reportdefaultBoxOptional.a?.b!=null ?defaultBoxOptional.a?.b :getFallbackBox();// should also reportdefaultBoxOptional.a?.b!=null ?defaultBoxOptional.a.b :getFallbackBox();
ESLint Config
module.exports={parser:"@typescript-eslint/parser",rules:{"@typescript-eslint/prefer-nullish-coalescing":"error",},};
tsconfig
{"compilerOptions": {"strictNullChecks":true }}
Expected Result
I expected all cases above to be reported with a suggested fix.
Actual Result
Only the first case (member-expression) is reported.
Additional Info
I think the third case (chain-expression with a member-expression as an alternate) is the more common case, asno-unnecessary-condition
will flag the second case (chain-expression).