Description
Before You File a Proposal Please Confirm You Have Done The Following...
- I have searched for related issues and found none that match my proposal.
- I have searched the current rule list and found no rules that match my proposal.
- I have read the FAQ and my problem is not listed.
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
:
- Enhancement: [no-unnecessary-type-parameters] Special case tuples and parameter arrays as a "single use" generic type #9529 itself: changing the default behavior of the rule
- This issue, separately: adding an opt-in option to mark some more types as "single-use"
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.
💖