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
interface Box {
value: string;
}
declare function getFallbackBox(): Box;
declare const defaultBox: { a: { b: Box | undefined } };
declare const defaultBoxOptional: { a?: { b?: Box | undefined } };
// reports correctly
defaultBox.a.b != null ? defaultBox.a.b : getFallbackBox();
// should report
defaultBoxOptional.a?.b != null ? defaultBoxOptional.a?.b : getFallbackBox();
// should also report
defaultBoxOptional.a?.b != null ? defaultBoxOptional.a.b : getFallbackBox();
ESLint Config
module.exports = {
parser: "@typescript-eslint/parser",
rules: {
"@typescript-eslint/prefer-nullish-coalescing": "error",
},
};
tsconfig
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, as no-unnecessary-condition
will flag the second case (chain-expression).