Repository navigation
Fix assignment-target detection through type assertions - #64965
Open
Cheng (chengchuu) wants to merge 2 commits into
Open
Cheng (chengchuu) wants to merge 2 commits into
Cheng (chengchuu) wants to merge 2 commits into
Conversation
Cheng (chengchuu)
force-pushed
the
fix/assertion-assignment-targets
branch
4 times, most recently
from
December 4, 2026 10:20
d77b20f to
66c1d58
Compare
Cheng (chengchuu)
force-pushed
the
fix/assertion-assignment-targets
branch
from
December 5, 2026 09:41
66c1d58 to
0835223
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #62127
Recognize assignment targets through
asand angle-bracket assertions so the Go compiler no longer reports false TS2454 ("used before being assigned") diagnostics on plain writes. This follows #62128 and adds the const and readonly assignment tests requested by Jake Bailey and Ryan Cavanaugh. This example now compiles without errors.Genuine uninitialized reads still report errors. Assignment checks now catch writes through assertions to constants, readonly properties, class bindings, and restricted generic indexes. The
resolutionCache.tsfixture casts the cache object to a mutable type so it can still update the readonly property in place.A read after an assertion-wrapped assignment can still report TS2454.
Validation
The fixture covers plain and compound writes through assertions, uninitialized reads, and invalid assignments.
affbdd7c790835223177I ran these tests from the repository root:
The standalone reproduction reported TS2454 before the fix. It compiled without diagnostics using a compiler built from
0835223177.AI assistance: Copilot helped generate the regression tests. I reviewed the changes and will handle any review feedback or revisions myself.