Skip to content

Bug: [prefer-optional-chain] should report case that can be converted to optional function call ?.() #11270

Open
@kirkwaiblinger

Description

@kirkwaiblinger

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

https://typescript-eslint.io/play/#ts=5.6.3&fileType=.tsx&code=CYUwxgNghgTiAEYD2A7AzgF3gMyUgXPAN4BQ88AtiBgBZLCECuKo2AliiMPAD7wAU-AJTwAvAD54ANyRtgQkgF8SJXEgB0VWvXgAyXTjybqdYMIDcQA&eslintrc=N4AhCgwIgJwVwDYFMDOUBcJiTCKABAFwE8AHVAYxgEtTCBaVBagO0IHpSYkAzJGegHs61QSwCGCehQAW41hjwB3cTBZQcAX3CagA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eFYDAruuGAL4g9A&tokens=false

Repro Code

declare const foo: {
  method: undefined | (() => void)
}

foo.method && foo.method();

ESLint Config

module.exports = {  
  "rules": {
    "@typescript-eslint/prefer-optional-chain": "warn"
  }
}

tsconfig

{
  "compilerOptions": {
    "strict": true
  }
}

Expected Result

I expect that the rule should report and suggest foo.method?.().

Actual Result

No report

Additional Info

This is specifically implied in the docs examples with the line foo && foo.a && foo.a.b && foo.a.b.method && foo.a.b.method();

Relates to #9605

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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy