Skip to content

Commit bacd28d

Browse files
committed
handle type aliases higher up
1 parent 469e933 commit bacd28d

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

packages/eslint-plugin/src/rules/no-unnecessary-type-parameters.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,13 @@ function collectTypeParameterUsageCounts(
258258
}
259259
}
260260

261+
// Catch-all: generic type references like `Exclude<T, null>`
262+
else if (type.aliasTypeArguments) {
263+
// We don't descend into the definition of the type alias, so we don't
264+
// know whether it's used multiple times. It's safest to assume it is.
265+
visitTypesList(type.aliasTypeArguments, true);
266+
}
267+
261268
// Intersections and unions like `0 | 1`
262269
else if (tsutils.isUnionOrIntersectionType(type)) {
263270
visitTypesList(type.types, assumeMultipleUses);
@@ -288,9 +295,6 @@ function collectTypeParameterUsageCounts(
288295
else if (tsutils.isConditionalType(type)) {
289296
visitType(type.checkType, assumeMultipleUses);
290297
visitType(type.extendsType, assumeMultipleUses);
291-
type.aliasTypeArguments?.forEach(typeArgument =>
292-
visitType(typeArgument, false),
293-
);
294298
}
295299

296300
// Catch-all: inferred object types like `{ K: V }`.
@@ -310,10 +314,6 @@ function collectTypeParameterUsageCounts(
310314
}
311315
}
312316

313-
for (const typeArgument of type.aliasTypeArguments ?? []) {
314-
visitType(typeArgument, true);
315-
}
316-
317317
visitType(type.getNumberIndexType(), true);
318318
visitType(type.getStringIndexType(), true);
319319

@@ -332,11 +332,6 @@ function collectTypeParameterUsageCounts(
332332
else if (isOperatorType(type)) {
333333
visitType(type.type, assumeMultipleUses);
334334
}
335-
336-
// Catch-all: generic type references like `Exclude<T, null>`
337-
else if (type.aliasTypeArguments) {
338-
visitTypesList(type.aliasTypeArguments, true);
339-
}
340335
}
341336

342337
function incrementIdentifierCount(

0 commit comments

Comments
 (0)
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