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
- I have tried restarting my IDE and the issue persists.
- I have updated to the latest version of the packages.
- I haveread the FAQ and my problem is not listed.
{"rules": {"@typescript-eslint/no-unnecessary-condition": ["error" ], }}
letfoo:string;constsetFoo=():void=>{if(foo?.length<1){foo='foo';}};
tsconfig
{ "compilerOptions": { "outDir": "./lib", "module": "commonjs", "target": "es2015", "lib": ["es6", "es7"], "sourceMap": true, "allowJs": false, "moduleResolution": "node", "forceConsistentCasingInFileNames": true, "noImplicitReturns": true, "noImplicitThis": true, "noImplicitAny": true, "strict": true, "strictNullChecks": true, "suppressImplicitAnyIndexErrors": true, "noUnusedLocals": true, "noErrorTruncation": true, "pretty": true, "declaration": true }, "include": [ "src/**/*" ]}
Expected Result
Existence check on a possibly uninitialized variable should not trigger no-unnecessary-condition
For sure, the type might be extended tolet foo = string | undefined;
as workaround, but that actually looks a bit uncommon for a let definition, where not initializing might be intended.
Actual ResultUnnecessary optional chain on a non-nullish value @typescript-eslint/no-unnecessary-condition
Versions
package | version |
---|---|
@typescript-eslint/eslint-plugin | 5.10.0 |
@typescript-eslint/parser | 5.10.0 |
TypeScript | 4.5.5 |
ESLint | 8.7.0 |
ts-node | 10.4.0 |