Skip to content

Bug: @typescript-eslint/prefer-nullish-coalescing Cannot read properties of undefined (reading 'some') #8293

@ODGodinho

Description

@ODGodinho

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=.ts&code=MYewdgzgLgBFIBECGUkFUBKAZA8gJwEsBzAsJAGxgF4YAJAFQFksBhJMANyQgFFyBTALb8wUAHQAHPCHhQAnhP5j4yVJiwBuAFBaAZgFcwwKAXAx%2BADySCJAgBQATFEgBcMQwGswIAO5gAlG6e3n4wAN5aMDB4-FD6eGBwiM7q%2BMSkFGJIErZyjs4wAD6FMABEUAAWBBCl-toAvjA6oJAgAmLkIER2lta2-HVaQA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Y6RAM0WlqYSNkAC1pkA9gEMkyMswDm6KL2jjokcGAC%2BAGk2Rik6Ml5K8RUrKo16yRi3ZGT6vTkPHeAeRqVxTVBhY2JCIZAC2kgBiiJL4sJwBmJrYwQBWyAAeSvhwiMnarsEA7kZMnkwAqv6wxMRq%2BIgAJgAqJIgAyhTU%2BABqvMi%2BTEpc0iaFOKERfcaDSgBMAAxzc%2BNQyOLxZIitpGZh4o0IiJCrBqqpofhKANr5OPiyflyU8gB06X4aKQC6mlogWiAA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkAhqqrAO4BSZlAZgyegDTga9VMzoBPEgGU8mZNDwUwMgK79BtACbpoqOpjoFiilWppR08ZHgAi22Prz2Asujx0NBuscyqBZyOgkTrAayhgAkkR4WLCI3r7q5gAeiFjI8OhRDLZwDvYcSj6mQpz20OgAwsQkyCTRURV0NUQA5pEAYmjoAHJ0GQUmfkLIRNCYFpluqPHFtKjIAEaKANqJmgiQQ-6BAKyba%2BYkAGz7ZrSBROhJCokAultQ8CFh6IqQRCHoAIwnD5BPoQwACVArBUMpDEQ3t1Pj9TkJLswADIjV6USCoTjw2gfdoMVB4AAWmFgyhahMavBIkUkzCs0EJMz%2BH3CSHm0CsAEEiGImYl3rBWYh2VYQXhlJhSHz-Cy2XIrAAVQm1aUI2AAVSIyl4GiRsGgPFVOI1Wp1AAU9H1XFgBkU-ohxrxMAA3SrVPAAUS18FtCX84yerqq8AyUQK3FQvD%2BjrBrvYxGCgLRhT9QhIpMw5ScdDilEG-LqsnkRqghbkeHaylGkIVYlSvtmpZk5e6YVQFUJ2gA1g2-mX5GaSalMHgxJErMgGMgAF4GQhQvN2-luTAtVxvQIAJgADJvN9ioKP6ysDgKtJA7oIAL5DSB4EgAWg%2B58o1BKXQb15AV6AA&tokens=false

Repro Code

const toDataURLOriginal = HTMLCanvasElement.prototype.toDataURL;

function example(data: unknown): unknown {
    return toDataURLOriginal.apply(data || "this");
}

console.log(example);

ESLint Config

module.exports = {
  "rules": {
    "@typescript-eslint/prefer-nullish-coalescing": "error"
  },
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "ecmaFeatures": {
        "jsx": true
    },
    "warnOnUnsupportedTypeScriptVersion": false,
    "ecmaVersion": 2022,
    "sourceType": "module",
    "project": [
      "tsconfig.json"
    ]
  }
};

tsconfig

{
  "compilerOptions": {
    "allowJs": false,
    "alwaysStrict": true,
    "declaration": true,
    "emitDecoratorMetadata": true,
    "esModuleInterop": true,
    "experimentalDecorators": true,
    "forceConsistentCasingInFileNames": true,
    "incremental": true,
    "lib": [
      "dom",
      "es5",
      "es6",
      "esnext"
    ],
    "module": "node16",
    "moduleResolution": "Node16",
    "newLine": "lf",
    "noFallthroughCasesInSwitch": true,
    "noImplicitAny": true,
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "preserveConstEnums": true,
    "removeComments": false,
    "resolveJsonModule": true,
    "sourceMap": true,
    "strict": true,
    "strictFunctionTypes": true,
    "strictNullChecks": true,
    "strictPropertyInitialization": true,
    "target": "es2022",
    "types": [
      "node"
    ],
    "baseUrl": ".",
    "outDir": "./dist",
    "rootDirs": [
        ".",
        "./source/"
    ],
    "typeRoots": [
        "./source/@types",
        "node_modules/@types"
    ],
  },
  "ts-node": {
    "files": true
  }
}

Expected Result

Done

Actual Result

TypeError: Cannot read properties of undefined (reading 'some')
Occurred while linting /home/dev/projetos/XXX-SDK/source/teste.ts:4
Rule: "@typescript-eslint/prefer-nullish-coalescing"
at LogicalExpression[operator = "||"] (/home/dev/projetos/XXX-SDK/node_modules/@typescript-eslint/eslint-plugin/dist/rules/prefer-nullish-coalescing.js:267:32)
at ruleErrorHandler (/home/dev/projetos/XXX-SDK/node_modules/eslint/lib/linter/linter.js:1076:28)
at /home/dev/projetos/XXX-SDK/node_modules/eslint/lib/linter/safe-emitter.js:45:58
at Array.forEach ()
at Object.emit (/home/dev/projetos/XXX-SDK/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
at NodeEventGenerator.applySelector (/home/dev/projetos/XXX-SDK/node_modules/eslint/lib/linter/node-event-generator.js:297:26)
at NodeEventGenerator.applySelectors (/home/dev/projetos/XXX-SDK/node_modules/eslint/lib/linter/node-event-generator.js:326:22)
at NodeEventGenerator.enterNode (/home/dev/projetos/XXX-SDK/node_modules/eslint/lib/linter/node-event-generator.js:340:14)
at CodePathAnalyzer.enterNode (/home/dev/projetos/XXX-SDK/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:803:23)
at /home/dev/projetos/XXX-SDK/node_modules/eslint/lib/linter/linter.js:1111:32
error Command failed with exit code 2.

Additional Info

yarn eslint --plugin @typescript-eslint --rule '{"@typescript-eslint/prefer-nullish-coalescing": "error"}' --parser "@typescript-eslint/parser" --parser-options '{project: ["tsconfig.json"]}' source/example.ts

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