Skip to content

Bug: [no-base-to-string] ignoredTypeNames doesn't work with generic types #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

    bugSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugintriageWaiting for team members to take a look

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy