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

Bug: [no-unnecessary-condition] Improper checking of optional chaining of defined method return value #7912

Closed
Labels
accepting prsGo ahead, send a pull request that resolves this issuebugSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin
@profaurore

Description

@profaurore

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

Playground Link

Repro Code

typeT1={y:()=>number}|null;declareconstx1:T1;x1?.y()?.toExponential();//     ^^//     Error expected for unnecessary optional chaining.typeT2=(()=>number)|undefined;declareconstx2:T2;x2?.()?.toExponential();//    ^^//     Error expected for unnecessary optional chaining.typeT3={y:number}|null;declareconstx3:T3;x3?.y?.toExponential();//   ^^//   Error correctly caught.typeT4=()=>number;declareconstx4:T4;x4()?.toExponential;//  ^^//  Error correctly caught.

ESLint Config

module.exports={parser:"@typescript-eslint/parser",rules:{"@typescript-eslint/no-unnecessary-condition":"error",},};

tsconfig

{"compilerOptions": {"strictNullChecks":true  }}

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.

Additional Info

This is partially related to#1977 and#2111.

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issuebugSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp