Skip to content

Enhancement: [no-unnecessary-type-parameters] Special case tuples and parameter arrays as a "single use" generic type #9529

Closed
@danvk

Description

@danvk

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

For purposes of counting whether a generic type parameter is used twice, T[] / Array<T> should only count as using it once. I'm not aware of any realistic scenario where this would lead to a false positive.

We decided to defer this to a follow-up in the initial implementation (see links below). So here's an official request for the follow-up.

Fail

declare function getLength<T>(xs: readonly T[]): number;

Pass

declare function getLength(xs: readonly unknown[]): number;

Additional Info

See https://twitter.com/jfet97/status/1810703565280759964 and #8173 (comment) for context on why this doesn't work as expected today.

See #8173 (comment) for previous discussion of special-casing Array and friends.

See #8173 (review) for a contrived example of how this could yield a false positive for Map.

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 rulelocked 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