Skip to content
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

Bug: prefer-optional-chain throws error: "Unexpected member object type: TSAsExpression" #6068

Closed
4 tasks done
revelt opened this issue Nov 23, 2022 · 3 comments
Closed
4 tasks done
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@revelt
Copy link

revelt commented Nov 23, 2022

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=4.9.3&sourceType=module&code=JYOwLgpgTgZghgYwgAgCoHsDWETIN4BQyymoAJgPwBcyAzmFKAOYDcBAvgTAK4gJjB0uenChhaqOEwAUYLDhoZsIAJQ0ARunQAbCHFyFiUCGG5RcAQgvSixZNbnLkcWs5ABPFQDpSIMsgAfAPsAbQAiMnR+dwAHCDCAGmQwgA8AW20wgF0vUARtbjIIWmlZeVwXN08fchVbFTZOAggUmPQxZCL4bm0wOjBRcUlWAiA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Y6RAM0WloHsalfkwCG8WmQAWo5uii9o-aJHBgAviHVA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA

Repro Code

interface Token {
  kind?: string;
}
function startsTag(token: Token): boolean {
  return !!(
    !(token as any).kind || !["doctype", "xml"].includes((token as any).kind)
  );
}

export default startsTag;

for reference, the full source is here



### ESLint Config

```javascript
module.exports = {
  parser: "@typescript-eslint/parser",
  rules: {
    "@typescript-eslint/prefer-optional-chain": "error"
  },
};

tsconfig

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

Expected Result

Expected ESLint not to throw

Actual Result

In VSCode ESLint throws with a message "Unexpected member object type: TSAsExpression":

Screenshot 2022-11-23 at 08 56 27

The playground error is more cryptic:

Screenshot 2022-11-23 at 08 58 16

Additional Info

I suspect it's from v5.44 release, and it might be a similar-class bug to #5553

Versions

package version
@typescript-eslint/eslint-plugin ^5.44.0
@typescript-eslint/parser ^5.44.0
TypeScript ^4.8.4
ESLint ^8.28.0
node 16.14.2
@revelt revelt added bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Nov 23, 2022
@JoshuaKGoldberg JoshuaKGoldberg added accepting prs Go ahead, send a pull request that resolves this issue and removed triage Waiting for maintainers to take a look labels Nov 23, 2022
@omril1
Copy link
Contributor

omril1 commented Nov 23, 2022

Seems related to #6024 as well.
The enhancement to the rule caused a lot of possible node types to break it 😞

@revelt
Copy link
Author

revelt commented Nov 30, 2022

The new v5.45 is still affected. The last working version is v5.42.

@bradzacher
Copy link
Member

This should now be fixed (the above playground is not crashing)

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

No branches or pull requests

4 participants