Repository navigation
fix(no-unnecessary-type-parameters): count generic type arguments - #1297
Conversation
|
@camc314 would you be able to review these compatibility fixes and approve the pending fork workflows? This PR covers generic type-argument reuse; #1298 covers Promise.finally callbacks; #1299 prevents value comparisons from becoming restarted optional-chain guards. Each has regressions that fail before the change, and full |
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0da35ae83a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4a7a7baad0
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| case ast.KindTypeReference, ast.KindExpressionWithTypeArguments, ast.KindImportType, ast.KindTypeQuery: | ||
| isArray := false | ||
| if ast.IsTypeReferenceNode(parent) { | ||
| isArray = checker.Checker_isArrayType(ctx.TypeChecker, ctx.TypeChecker.GetTypeAtLocation(parent)) |
There was a problem hiding this comment.
Preserve aliases when excluding built-in arrays
When a generic alias resolves to a built-in array—for example type Pair<X> = Array<[X, X]>; declare function f<K, T>(k: K): K extends string ? Pair<T> : never—GetTypeAtLocation(Pair<T>) is itself classified as an array, so this branch bypasses the new generic-argument safeguard. The downstream conditional-type visitor only walks the check and extends types, not the true/false branches, and therefore reports T as unused even though the alias expands to two uses; inspect alias metadata before applying the array exception so only direct built-in Array/ReadonlyArray references stay on the type-aware path.
Useful? React with 👍 / 👎.
Summary
no-unnecessary-type-parametersreportsTas never used in this signature even though a generic alias uses it:The AST fast path currently only counts repeated identifiers. Mirror typescript-eslint’s existing type-argument safeguard: a parameter used as a generic type argument may be reused inside that type and must not be reported. This also avoids losing uses hidden in conditional return branches. Keep
ArrayandReadonlyArrayin the type-aware path, where single-use parameters can still be reported.Testing
Array<T>andReadonlyArray<T>controls, including their suggestions. Existing snapshots are unchanged; only the two new controls add snapshots.just readypasses: formatting, golangci-lint, E2E tests, and all Go tests.AI assistance: prepared and validated with Codex.