Skip to content

fix(no-unnecessary-type-parameters): count generic type arguments - #1297

Merged
camc314 merged 3 commits into
oxc-project:mainfrom
farnoodma:fix/type-parameter-type-argument-usage
Oct 21, 2026
Merged

camc314 merged 3 commits into
oxc-project:mainfrom
farnoodma:fix/type-parameter-type-argument-usage

Conversation

@farnoodma

Copy link
Copy Markdown
Contributor

Summary

no-unnecessary-type-parameters reports T as never used in this signature even though a generic alias uses it:

type Pair<T> = [T, T];
declare function makePair<K, T>(kind: K): K extends string ? Pair<T> : never;

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 Array and ReadonlyArray in the type-aware path, where single-use parameters can still be reported.

Testing

  • All four new valid regressions fail on main before the implementation change, covering both conditional branches, a parenthesized argument, and nested conditional aliases.
  • Added invalid Array<T> and ReadonlyArray<T> controls, including their suggestions. Existing snapshots are unchanged; only the two new controls add snapshots.
  • just ready passes: formatting, golangci-lint, E2E tests, and all Go tests.

AI assistance: prepared and validated with Codex.

@farnoodma

farnoodma commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor Author

@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 just ready passes separately on all three branches. I selected you based on your recent work on these rules; thanks for taking a look.

@camc314

camc314 commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-21T17:02:03.709644Z 4a7a7ba New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

@camc314 camc314 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@camc314
camc314 enabled auto-merge (squash) October 21, 2026 16:59

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@camc314
camc314 merged commit e649c1e into oxc-project:main Oct 21, 2026
8 checks passed
@farnoodma
farnoodma deleted the fix/type-parameter-type-argument-usage branch October 22, 2026 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants