Skip to content

Bug: [no-unnecessary-type-parameters] misleading error messages #9664

@kirkwaiblinger

Description

@kirkwaiblinger

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=.ts&code=GYVwdgxgLglg9mABABwIYCcDOBTAUphAHgBVFsAPKbMAE00UynRjAHMA%2BACheRCgC4GTFqwCUg0gG8AUIkTpsUEOiS4AygHkAcgDo0WbNzC8ooxKnrEA3NIC%2BQA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1tiacTJTIAhtEK0ipWsRFCAtonyJoqDJCXQO0SODABfELqA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eFYDAruuGAL4g9A&tokens=false

Repro Code

// T is used twice - maybe it should say "once in the signature"?
function parseJson<T extends string>(input: string): T {
  return JSON.parse(input) as T;
}

// T is used zero times
function parseJson<T extends string>(input: string): any {
  return JSON.parse(input) as any;
}

ESLint Config

{
  "rules": {
    "@typescript-eslint/no-unnecessary-type-parameters": "error"
  }
}

tsconfig

{
  "compilerOptions": {
    "strict": true
  }
}

Expected Result

I expect the error message should reflect correctly the number of times the type parameter is used.

Actual Result

"Type parameter T is used only once." in both cases

Additional Info

Let's also include a doc change to the docs page, if counting parameters is only supposed to be counting the usages in the signature?

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issuebugSomething isn't workinglocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.package: 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

      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