Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Enhancement: [no-unnecessary-type-parameters] Add an option to treat types as "single-use" #9793

Open
@JoshuaKGoldberg

Description

@JoshuaKGoldberg

Before You File a Proposal Please Confirm You Have Done The Following...

My proposal is suitable for this project

  • I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).

Link to the rule's documentation

https://typescript-eslint.io/rules/no-unnecessary-type-parameters

Description

Splitting out of #9536 (comment) -> #9529 (comment), there are two usability improvements we'd like for @typescript-eslint/no-unnecessary-type-parameters:

For context, the rule right now is surprisingly limited in functionality because of types like arrays actually having multiple uses of their type parameters: https://typescript-eslint.io/rules/no-unnecessary-type-parameters/#limitations. Being able to mark known safe types as "single-use" would let people opt into a stricter form of the rule.

Fail

/* @typescript-eslint/no-unnecessary-type-parameters: "error", { "allow": [{ "from": "lib", "name": "Array" }] */
class ClassyArray<T> {
  arr: T[];
}

Pass

/* @typescript-eslint/no-unnecessary-type-parameters: "error" */
class ClassyArray<T> {
  arr: T[];
}

Additional Info

I think we'd want to special-case the report message for the rule in these cases. If someone is using it configured to ignore arrays, then is surprised that it complains on a construct using arrays, they should know it's from their custom config - not faulty rule logic.

💖

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issueenhancement: plugin rule optionNew rule option for an existing eslint-plugin rulepackage: 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