Skip to content

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

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

Closed
4 tasks done
ODGodinho opened this issue Jan 23, 2024 · 1 comment
Labels
bug Something isn't working duplicate This issue or pull request already exists package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@ODGodinho
Copy link

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

@ODGodinho ODGodinho added bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Jan 23, 2024
@auvred
Copy link
Member

auvred commented Jan 23, 2024

Duplicate of #8261

@bradzacher bradzacher added duplicate This issue or pull request already exists and removed triage Waiting for team members to take a look labels Jan 24, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working duplicate This issue or pull request already exists package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

No branches or pull requests

3 participants