Skip to content

Bug: [no-base-to-string] hit URL object but should not #4999

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
HolgerJeromin opened this issue May 17, 2022 · 6 comments · Fixed by #5839
Closed
4 tasks done

Bug: [no-base-to-string] hit URL object but should not #4999

HolgerJeromin opened this issue May 17, 2022 · 6 comments · Fixed by #5839
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

@HolgerJeromin
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=4.7.1-rc&sourceType=module&code=BQOwpg7gBAogTnA9nYByARkg1mEqCU+AdAC6IDKJcAliAObD5A&rules=N4IgAgLgngDgpgZwMYCcCWMIFpEBs0B2EA9AQPZYBGAhgnFhBQhOgQOYgBcIcKKZKEAF8gA&tsConfig=N4XyA

Repro Code

(new Error('broken')).toString()

ESLint Config

module.exports = {
  parser: "@typescript-eslint/parser",
  rules: {
    "@typescript-eslint/no-base-to-string": ["error"],
  },
};

tsconfig

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

Expected Result

The code should be fine as the runtime output is:
'Error: broken'

Actual Result

eslint reports:
'new Error('broken') will evaluate to '[object Object]' when stringified.ESLint (@typescript-eslint/no-base-to-string)

Additional Info

No response

Versions

package version
@typescript-eslint/eslint-plugin 5.24.0
@typescript-eslint/parser 5.24.0
TypeScript 4.6.2
ESLint 8.15.0
@HolgerJeromin HolgerJeromin 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 May 17, 2022
@JoshuaKGoldberg JoshuaKGoldberg added accepting prs Go ahead, send a pull request that resolves this issue triage Waiting for team members to take a look and removed triage Waiting for team members to take a look accepting prs Go ahead, send a pull request that resolves this issue labels May 17, 2022
@JoshuaKGoldberg
Copy link
Member

JoshuaKGoldberg commented May 17, 2022

Indeed, this is a bug on the TypeScript side: #1655; microsoft/TypeScript#30225; microsoft/TypeScript#38347. They've been hesitant to fix it there because lib.d.ts changes have a tendency to break other users in surprising ways.

Right now the rule hardcodes boolean types to being allowed.
I think at this point we should add special case handling for the built-in Error and URL as well.

// Patch for old version TypeScript, the Boolean type definition missing toString()

For now the rule does have an ignoredTypeNames option that you can use.

{
  "rules": {
    "no-base-to-string": ["error", {
      "ignoredTypeNames": ["Error", "URL"]
    }]
  }
}

Edit: per #5323, URLSearchParams too.

@armano2

This comment was marked as outdated.

@JoshuaKGoldberg

This comment was marked as outdated.

@JoshuaKGoldberg JoshuaKGoldberg changed the title Bug: [no-base-to-string] hit Error object but should not Bug: [no-base-to-string] hit URL object but should not May 31, 2022
@armano2

This comment was marked as outdated.

@bradzacher

This comment was marked as outdated.

@armano2

This comment was marked as outdated.

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
4 participants