Skip to content

fix(no-unnecessary-type-assertion): avoid contextual generic inference for call expressions#824

Merged
graphite-app[bot] merged 1 commit intomainfrom
c/03-23-fix_no-unnecessary-type-assertion_avoid_contextual_generic_inference_for_call_expressions
Mar 23, 2026
Merged

fix(no-unnecessary-type-assertion): avoid contextual generic inference for call expressions#824
graphite-app[bot] merged 1 commit intomainfrom
c/03-23-fix_no-unnecessary-type-assertion_avoid_contextual_generic_inference_for_call_expressions

Conversation

@camc314
Copy link
Copy Markdown
Contributor

@camc314 camc314 commented Mar 23, 2026

For call-like expressions, the assersion was infering the actual type.

This is fixed by asking the checker for the context-free expression type before comparing it withith the asserted type.

fixes oxc-project/oxc#20656

Copy link
Copy Markdown
Contributor Author

camc314 commented Mar 23, 2026


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 23, 2026 17:38
Copilot AI review requested due to automatic review settings March 23, 2026 17:38
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes false positives in no-unnecessary-type-assertion where type assertions on call-like expressions could incorrectly influence contextual generic inference during type comparison.

Changes:

  • Use a context-free expression type for call-like expressions before comparing against the asserted type.
  • Add a regression test covering querySelector overloads where contextual typing previously leaked through an 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 Adjusts the rule’s type acquisition to avoid contextual inference for call-like expressions.
internal/rules/no_unnecessary_type_assertion/no_unnecessary_type_assertion_test.go Adds a regression test for overload + assertion inference leakage (issue #20656).

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

@camc314 camc314 self-assigned this Mar 23, 2026
Copy link
Copy Markdown
Contributor Author

camc314 commented Mar 23, 2026

Merge activity

…e for call expressions (#824)

For call-like expressions, the assersion was infering the actual type.

This is fixed by asking the checker for the context-free expression type before comparing it withith the asserted type.

fixes oxc-project/oxc#20656
@graphite-app graphite-app bot force-pushed the c/03-23-fix_no-unnecessary-type-assertion_avoid_contextual_generic_inference_for_call_expressions branch from 701cd88 to 599e150 Compare March 23, 2026 17:50
@graphite-app graphite-app bot merged commit 599e150 into main Mar 23, 2026
7 of 8 checks passed
@graphite-app graphite-app bot deleted the c/03-23-fix_no-unnecessary-type-assertion_avoid_contextual_generic_inference_for_call_expressions branch March 23, 2026 17:57
@graphite-app graphite-app bot removed the 0-merge label Mar 23, 2026
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 typeAware enabled

2 participants