Skip to content

Docs: [no-base-to-string] erroneously refers to regular expressions #11420

@tyilo

Description

@tyilo

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.8.2&fileType=.ts&code=MYGwhgzhAEBaD2ATAogJ1fVAeAKtAvNAK4B2A1ifAO4kB80A3gL4BQLALqgJ6MvTQB6AdAB0Ylk2jAw7YAAtoACgCmASl78AlgDMly6JpIR2YEsGXxdCFOkzqGfftDAhlqdipHt4AZU6GAc0VVVQBuR1YmIA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1oCMBDZRLXxdk%2BKkwDm6MAG1w2HImjQO0SABp5CrAuyRKEztEQATAColEAOV4BbFNLm7dkAKLLVGrc6gAlRBKuAB7EXj56AKq%2BADJh4VBR0QDKiLzQZAAWAAppdqjeCgC6BWAAvt7FEOWlQA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

class ZodError<T = unknown> {}

try {
  // ...
} catch (e) {
  if (e instanceof ZodError) {
    alert(e.toString());
  }
}

ESLint Config

module.exports = {
  "rules": {
    "@typescript-eslint/no-base-to-string": [
      "error",
      {
        "ignoredTypeNames": [
          "Error",
          "RegExp",
          "URL",
          "URLSearchParams"
        ]
      }
    ]
  }
}

tsconfig

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

Expected Result

The lint should be ignored due to the ignoredTypeNames.

Actual Result

The lint is triggered:

'e' will use Object's default stringification format ('[object Object]') when stringified. 7:11 - 7:12

Additional Info

I got this error when upgrading zod from v3 to v4.

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issuedocumentationDocumentation ("docs") that needs adding/updatingpackage: 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