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 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
type T1 = { y: () => number } | null;
declare const x1: T1;
x1?.y()?.toExponential();
// ^^
// Error expected for unnecessary optional chaining.
type T2 = (() => number) | undefined;
declare const x2: T2;
x2?.()?.toExponential();
// ^^
// Error expected for unnecessary optional chaining.
type T3 = { y: number } | null;
declare const x3: T3;
x3?.y?.toExponential();
// ^^
// Error correctly caught.
type T4 = () => number;
declare const x4: T4;
x4()?.toExponential;
// ^^
// Error correctly caught.
ESLint Config
module.exports = {
parser: "@typescript-eslint/parser",
rules: {
"@typescript-eslint/no-unnecessary-condition": "error",
},
};
tsconfig
Expected Result
On lines 3 and 9, I expected there to be an error when using optional chaining on the return value of a method that returns a non-null and non-undefined value following another optional chaining.
Actual Result
On lines 3 and 9, no error was reported.