Skip to content

Bug: [prefer-promise-reject-errors (and other rules too)] Cannot convert Symbol to string (8.6.0 regression) #9999

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
AviVahl opened this issue Sep 16, 2024 · 5 comments · Fixed by #10004
Closed
4 tasks done
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@AviVahl
Copy link

AviVahl commented Sep 16, 2024

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.5.2&fileType=.tsx&code=KYDwDg9gTgLgBAYwDYEMDOa4FkVgErADmAlmjFAJ4A8A0gDRwAqAfHAN4BQccYArgEZJiCOMRjAAtpgC8cAHbAA7tly0GLABQBKANxceAoSIDaAZQoT%2BEJADoxwKChjQAutvb7uUYDF5Q5cDAAFqR24lJmFla29o7OUG66%2BgC%2BHKlAA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Y6RAM0Wlo4D2AW0rJEtTgCtEZOr2gDoqDJHmLI4MAF8QWoA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

export class MapRegistry<K, T> {
  public items = new Map<K, T>();
  public [Symbol.iterator]() {
    return this.items[Symbol.iterator]();
  }
}

ESLint Config

{
  "rules": {
    "@typescript-eslint/prefer-promise-reject-errors": "error"
  }
}

tsconfig

{
  "compilerOptions": {
    // ...
  }
}

Expected Result

lint should pass

Actual Result

TypeError: Cannot convert a Symbol value to a string

Additional Info

8.5.0 works fine

@AviVahl AviVahl 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 Sep 16, 2024
@kirkwaiblinger
Copy link
Member

Oh, this sounds like #9836, see also #8386

@kirkwaiblinger kirkwaiblinger added accepting prs Go ahead, send a pull request that resolves this issue and removed bug Something isn't working labels Sep 16, 2024
@kirkwaiblinger
Copy link
Member

cc @abrahamguo

@kirkwaiblinger
Copy link
Member

99% certain the root cause is that this code right here

const value = getStaticValue(key, sourceCode.getScope(node))?.value as
| string
| number
| null
| undefined;
return value == null ? undefined : `${value}`;

doesn't account for the fact that the static value can be a symbol, which will immediately throw when coerced to string

@JoshuaKGoldberg JoshuaKGoldberg added bug Something isn't working and removed triage Waiting for team members to take a look labels Sep 16, 2024
@JavaScriptBach
Copy link
Contributor

I also get TypeError: Cannot convert a Symbol value to a string when running @typescript-eslint/no-unnecessary-condition on Typescript-ESLint 8.6.0, with ESLint 8.57.0. Here is a stack trace if it's helpful:

TypeError: Cannot convert a Symbol value to a string
Occurred while linting <redacted>
Rule: "@typescript-eslint/no-unnecessary-condition"
    at getStaticMemberAccessValue (<redacted>/node_modules/@typescript-eslint/eslint-plugin/dist/util/misc.js:207:43)
    at isArrayMethodCallWithPredicate (<redacted>/node_modules/@typescript-eslint/eslint-plugin/dist/util/isArrayMethodCallWithPredicate.js:44:69)
    at checkCallExpression (<redacted>/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-unnecessary-condition.js:339:59)
    at ruleErrorHandler (<redacted>/node_modules/eslint/lib/linter/linter.js:1076:28)
    at <redacted>/node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (<redacted>/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (<redacted>/node_modules/eslint/lib/linter/node-event-generator.js:297:26)
    at NodeEventGenerator.applySelectors (<redacted>/node_modules/eslint/lib/linter/node-event-generator.js:326:22)
    at NodeEventGenerator.enterNode (<redacted>/node_modules/eslint/lib/linter/node-event-generator.js:340:14)

@abrahamguo
Copy link
Contributor

Sounds good. This will be an easy fix, I will plan on opening a PR with the fix in the next 12 hours unless someone beats me to it 😄

@kirkwaiblinger kirkwaiblinger changed the title Bug: [prefer-promise-reject-errors] crashes with specific code (8.6.0 regression) Bug: [prefer-promise-reject-errors (and other rules too)] Cannot convert Symbol to string (8.6.0 regression) Sep 16, 2024
@github-actions github-actions bot added the locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. label Oct 1, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 1, 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 locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
5 participants