diff --git a/packages/eslint-plugin/src/rules/no-unnecessary-type-parameters.ts b/packages/eslint-plugin/src/rules/no-unnecessary-type-parameters.ts index 02b51d184533..6b74879b0dfe 100644 --- a/packages/eslint-plugin/src/rules/no-unnecessary-type-parameters.ts +++ b/packages/eslint-plugin/src/rules/no-unnecessary-type-parameters.ts @@ -258,6 +258,13 @@ function collectTypeParameterUsageCounts( } } + // Catch-all: generic type references like `Exclude` + else if (type.aliasTypeArguments) { + // We don't descend into the definition of the type alias, so we don't + // know whether it's used multiple times. It's safest to assume it is. + visitTypesList(type.aliasTypeArguments, true); + } + // Intersections and unions like `0 | 1` else if (tsutils.isUnionOrIntersectionType(type)) { visitTypesList(type.types, assumeMultipleUses); @@ -307,10 +314,6 @@ function collectTypeParameterUsageCounts( } } - for (const typeArgument of type.aliasTypeArguments ?? []) { - visitType(typeArgument, true); - } - visitType(type.getNumberIndexType(), true); visitType(type.getStringIndexType(), true); @@ -329,11 +332,6 @@ function collectTypeParameterUsageCounts( else if (isOperatorType(type)) { visitType(type.type, assumeMultipleUses); } - - // Catch-all: generic type references like `Exclude` - else if (type.aliasTypeArguments) { - visitTypesList(type.aliasTypeArguments, true); - } } function incrementIdentifierCount( diff --git a/packages/eslint-plugin/tests/rules/no-unnecessary-type-parameters.test.ts b/packages/eslint-plugin/tests/rules/no-unnecessary-type-parameters.test.ts index 1ad76a9210d7..7e63e342f8fd 100644 --- a/packages/eslint-plugin/tests/rules/no-unnecessary-type-parameters.test.ts +++ b/packages/eslint-plugin/tests/rules/no-unnecessary-type-parameters.test.ts @@ -342,6 +342,24 @@ ruleTester.run('no-unnecessary-type-parameters', rule, { (token): token is Exclude => tokenType in conditions; `, + ` + type Foo = S extends 'somebody' + ? T extends 'once' + ? 'told' + : 'me' + : never; + + declare function foo(data: T): (other: S) => Foo; + `, + ` + type Foo = S extends 'somebody' + ? T extends 'once' + ? 'told' + : 'me' + : never; + + declare function foo(data: T): (other: S) => Foo; + `, ` declare function mapObj( obj: { [key in K]?: V }, 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