Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[no-unnecessary-condition] False error on uninitialized variable #4513

Closed
Labels
accepting prsGo ahead, send a pull request that resolves this issuebugSomething isn't workinglocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.package: eslint-pluginIssues related to @typescript-eslint/eslint-plugin
@Retro64

Description

@Retro64
  • 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.

Playground

{"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 Result
Unnecessary optional chain on a non-nullish value @typescript-eslint/no-unnecessary-condition

Versions

packageversion
@typescript-eslint/eslint-plugin5.10.0
@typescript-eslint/parser5.10.0
TypeScript4.5.5
ESLint8.7.0
ts-node10.4.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issuebugSomething isn't workinglocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.package: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp