fix(no-unnecessary-type-assertion): avoid inferring generic defaults from assertions#826
Conversation
How to use the Graphite Merge QueueAdd 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. |
There was a problem hiding this comment.
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>whereload<T = unknown>()would otherwise inferTfrom 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.
Merge activity
|
…from assertions (#826) fixes oxc-project/oxc#20682
494dcd8 to
f8a6ae2
Compare

fixes oxc-project/oxc#20682