Skip to content

Bug: [prefer-nullish-coalescing] TypeError: Cannot read properties of undefined (reading 'some') when left-hand-side is unknown #8276

Closed as not planned
@JoshuaKGoldberg

Description

@JoshuaKGoldberg

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.3.3&fileType=.tsx&code=CYUwxgNghgTiAEYD2A7AzgF3gNyhAriAFzz4oDWKSA7igNwBQuBCAPq-AN4C%2BjQA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Y6RAM0WlqYSNkAC1pkA9gEMkyMswDm6KL2jjokcGAC%2BILUA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

declare const value: unknown;
value || {};

ESLint Config

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

tsconfig

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

Expected Result

No crash. Perhaps a lint report.

Actual Result

TypeError: Cannot read properties of undefined (reading 'some')
Occurred while linting /input.tsx:2
Rule: "@typescript-eslint/prefer-nullish-coalescing"
    at LogicalExpression[operator = "||"] (https://typescript-eslint.io/sandbox/index.js:143:58720)
    at https://typescript-eslint.io/sandbox/index.js:106:2597
    at https://typescript-eslint.io/sandbox/index.js:100:32964
    at Array.forEach (<anonymous>)
    at Object.emit (https://typescript-eslint.io/sandbox/index.js:100:32953)
    at _x.applySelector (https://typescript-eslint.io/sandbox/index.js:41:22861)
    at _x.applySelectors (https://typescript-eslint.io/sandbox/index.js:41:23157)
    at _x.enterNode (https://typescript-eslint.io/sandbox/index.js:41:23248)
    at yx.enterNode (https://typescript-eslint.io/sandbox/index.js:35:23816)
    at https://typescript-eslint.io/sandbox/index.js:106:3033 2:1 - 2:12

Additional Info

Discovered in JoshuaKGoldberg/eslint-plugin-package-json#117.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingduplicateThis issue or pull request already existspackage: 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