Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Bug: [prefer-nullish-coalescing] internal error when linting on binary expression (||) with nullable type #7222

@JLHwung

Description

@JLHwung

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.

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