Skip to content

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

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
FloEdelmann opened this issue Feb 6, 2024 · 1 comment · Fixed by #8390
Closed
4 tasks done

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

FloEdelmann opened this issue Feb 6, 2024 · 1 comment · Fixed by #8390
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@FloEdelmann
Copy link
Contributor

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

@FloEdelmann FloEdelmann 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 Feb 6, 2024
@JoshuaKGoldberg JoshuaKGoldberg added accepting prs Go ahead, send a pull request that resolves this issue and removed triage Waiting for team members to take a look labels Feb 6, 2024
@kirkwaiblinger
Copy link
Member

well that's embarassing 😆
Will put up a fix shortly

kirkwaiblinger added a commit to kirkwaiblinger/typescript-eslint that referenced this issue Feb 6, 2024
JoshuaKGoldberg pushed a commit that referenced this issue Feb 6, 2024
…erting symbols to numbers (#8390)

* fix #8386: Stop throwing type errors when converting symbols to numbers

* Address PR feedback
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
3 participants