Skip to content

fix(no-unnecessary-type-assertion): avoid inferring generic defaults from assertions#826

Merged
graphite-app[bot] merged 1 commit into
mainfrom
c/03-24-fix_no-unnecessary-type-assertion_avoid_inferring_generic_defaults_from_assertions
Mar 24, 2026
Merged

fix(no-unnecessary-type-assertion): avoid inferring generic defaults from assertions#826
graphite-app[bot] merged 1 commit into
mainfrom
c/03-24-fix_no-unnecessary-type-assertion_avoid_inferring_generic_defaults_from_assertions

Conversation

@camc314

@camc314 camc314 commented Mar 24, 2026

Copy link
Copy Markdown
Contributor

camc314 commented Mar 24, 2026

Copy link
Copy Markdown
Contributor Author

How to use the Graphite Merge Queue

Add the label 0-merge to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@camc314 camc314 marked this pull request as ready for review March 24, 2026 08:53
Copilot AI review requested due to automatic review settings March 24, 2026 08:53

Copilot AI 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.

Pull request overview

Fixes a false-positive in no-unnecessary-type-assertion where a type assertion could incorrectly influence generic type inference (via contextual typing), causing the rule to think the assertion “doesn’t change the type” when it actually does—specifically for await-wrapped call-like expressions (per oxc-project/oxc#20682).

Changes:

  • Extend the rule’s “context-free type” handling to treat await-wrapped call/new/tagged-template expressions as context-sensitive for generic inference purposes.
  • Add a regression test covering (await load()) as Record<string, unknown> where load<T = unknown>() would otherwise infer T from the assertion.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
internal/rules/no_unnecessary_type_assertion/no_unnecessary_type_assertion.go Detect await-wrapped call-like expressions and use context-free typing to prevent assertion-driven generic inference.
internal/rules/no_unnecessary_type_assertion/no_unnecessary_type_assertion_test.go Add regression coverage for the await + generic-default-inference scenario.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@camc314 camc314 self-assigned this Mar 24, 2026

camc314 commented Mar 24, 2026

Copy link
Copy Markdown
Contributor Author

Merge activity

@graphite-app graphite-app Bot force-pushed the c/03-24-fix_no-unnecessary-type-assertion_avoid_inferring_generic_defaults_from_assertions branch from 494dcd8 to f8a6ae2 Compare March 24, 2026 09:06
@graphite-app graphite-app Bot merged commit f8a6ae2 into main Mar 24, 2026
7 of 8 checks passed
@graphite-app graphite-app Bot removed the 0-merge label Mar 24, 2026
@graphite-app graphite-app Bot deleted the c/03-24-fix_no-unnecessary-type-assertion_avoid_inferring_generic_defaults_from_assertions branch March 24, 2026 09:13
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.

linter: no-unnecessary-type-assertion false positive on generic functions with default type parameters

2 participants