Skip to content

Bug: [@typescript-eslint/prefer-optional-chain] why can't report error for "data && data.code === 0" #10938

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
4 tasks done
gaterking opened this issue Mar 11, 2025 · 1 comment
Labels
bug Something isn't working duplicate This issue or pull request already exists locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look

Comments

@gaterking
Copy link

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.8.2&fileType=.tsx&code=GYVwdgxgLglg9mABFApgZygCgCYEMq4BciA3hHNisWCALYBGKATgL6IA%2BiNANtwJSkAUIkQxgiHPlyIAZDMR4CAOnKVEAXk2IADAJLCRiJiiggmSYLm5oUAbgNsU1lEMNGTZpFCYg7DwSxAA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Y6RAM0WloHsalfkwCG8WmQAWo5uii9o-aJHBgAviHVA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

function test(data: {code: number} | null) {
  if (data && data.code === 0) {
    return false;
  } else {
    return true;
  }
}

ESLint Config

{
  "rules": {
    "@typescript-eslint/prefer-optional-chain": "error"
  }
}

tsconfig

{
  "compilerOptions": {
    // ...
  }
}

Expected Result

show error

Actual Result

why it show ok? I need the rult give some suggrest to optional-chain

Additional Info

No response

@gaterking gaterking added bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Mar 11, 2025
@kirkwaiblinger
Copy link
Member

Hi @gaterking !

I think this is a duplicate of #7170

@kirkwaiblinger kirkwaiblinger added the duplicate This issue or pull request already exists label Mar 11, 2025
@github-actions github-actions bot added the locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. label Mar 19, 2025
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 19, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working duplicate This issue or pull request already exists locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look
Projects
None yet
Development

No branches or pull requests

2 participants