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-nullish-coalescing] internal error when linting on binary expression (||) with nullable type #7222

Closed
4 tasks done
JLHwung opened this issue Jul 14, 2023 · 0 comments · Fixed by #7225
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

@JLHwung
Copy link

JLHwung commented Jul 14, 2023

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.1.6&fileType=.tsx&code=DYUwLgBAhgXBDOYBOBLAdgcwgHwmgrsMBALx6HADcAUKJAEZyKqY7lGntXXVQ671qQA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Y6RAM0WlqYSNkAC1pkA9gEMkyMswDm6KL2jjokcGAC%2BILUA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eFYDAruuGAL4g9A&tokens=false

Repro Code

let a: string | null = null;
let b: string | null = null;

a || b

ESLint Config

module.exports = {
  parser: "@typescript-eslint/parser",
  rules: {
    "@typescript-eslint/prefer-nullish-coalescing": "error"
  },
};

tsconfig

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

Expected Result

No internal errors

Actual Result

eslint throws when linting on the line a || b

TypeError: Cannot read properties of undefined (reading 'some')
Occurred while linting /input.tsx:4
Rule: "@typescript-eslint/prefer-nullish-coalescing"
    at LogicalExpression[operator = "||"] (https://typescript-eslint.io/sandbox/index.js:140:49356)
    at https://typescript-eslint.io/sandbox/index.js:105:2536
    at https://typescript-eslint.io/sandbox/index.js:99:32978
    at Array.forEach (<anonymous>)
    at Object.emit (https://typescript-eslint.io/sandbox/index.js:99:32967)
    at Sx.applySelector (https://typescript-eslint.io/sandbox/index.js:40:22861)
    at Sx.applySelectors (https://typescript-eslint.io/sandbox/index.js:40:23157)
    at Sx.enterNode (https://typescript-eslint.io/sandbox/index.js:40:23248)
    at ex.enterNode (https://typescript-eslint.io/sandbox/index.js:34:23858)
    at https://typescript-eslint.io/sandbox/index.js:105:2972 4:1 - 4:7

The error is probably thrown from

(type as ts.UnionOrIntersectionType).types.some(t =>

Additional Info

(I didn't figure out how to run the lint again with --debug flag on the playground)

The reproduction is extracted from the Babel source: https://github.com/babel/babel/blob/main/packages/babel-helper-create-class-features-plugin/src/features.ts, first reported here.

@JLHwung JLHwung 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 Jul 14, 2023
@JLHwung JLHwung changed the title Bug: [prefer-nullish-coalescing] <short description of the issue> Bug: [prefer-nullish-coalescing] internal error when linting on binary expression (||) with nullable type Jul 14, 2023
@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 Jul 14, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 25, 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
2 participants