Skip to content

Bug: [prefer-find] errors when trying to convert a Symbol value to a number #8386

Closed
@FloEdelmann

Description

@FloEdelmann

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=CYUwxgNghgTiAEAzArgOzAFwJYHtVJxwAoAHWKAWwC54pUBPAShrvoCg3FCiBleigEY4IAOi4wiAci45JjRkA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Y6RAM0Wlq%2BYATdFF7QA9tEjgwAXxCygA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

declare function foo(param: any): any

foo(Symbol.for('foo'))

ESLint Config

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

tsconfig

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

Expected Result

No lint error.

Actual Result

Locally the error message is more expressive than in the playground:

TypeError: Cannot convert a Symbol value to a number
Occurred while linting …/foo.ts:3
Rule: "@typescript-eslint/prefer-find"
    at Number (<anonymous>)
    at isTreatedAsZeroByArrayAt (…/node_modules/@typescript-eslint/eslint-plugin/dist/rules/prefer-find.js:129:30)
    at getObjectIfArrayAtExpression (…/node_modules/@typescript-eslint/eslint-plugin/dist/rules/prefer-find.js:114:39)
    at CallExpression (…/node_modules/@typescript-eslint/eslint-plugin/dist/rules/prefer-find.js:165:32)
    at ruleErrorHandler (…/node_modules/eslint/lib/linter/linter.js:1076:28)
    at …/node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (…/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector …/node_modules/eslint/lib/linter/node-event-generator.js:297:26)
    at NodeEventGenerator.applySelectors (…/node_modules/eslint/lib/linter/node-event-generator.js:326:22)

Additional Info

CC @kirkwaiblinger

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