Skip to content

Fix assignment-target detection through type assertions - #64965

Open
Cheng (chengchuu) wants to merge 1 commit into
microsoft:mainfrom
chengchuu:fix/assertion-assignment-targets
Open

Cheng (chengchuu) wants to merge 1 commit into
microsoft:mainfrom
chengchuu:fix/assertion-assignment-targets

Conversation

@chengchuu

Copy link
Copy Markdown

Summary

Fixes #62127

Fix false TS2454 ("used before being assigned") diagnostics on writes through as and angle-bracket assertions in the Go compiler. This follows #62128, including the const and readonly assignment coverage requested by Jake Bailey and Ryan Cavanaugh. The following code now compiles without errors:

function example() {
  let value: number;
  (value as number) = 1;
}

Assignment checks now apply through assertions. Previously accepted writes to constants, readonly properties, class bindings, and restricted generic indexes can therefore report errors. JavaScript emission is unchanged.

Added regression tests for ordinary and nested writes, uninitialized reads, compound assignments, const/readonly targets, and mutable-object casts. Existing scenarios are preserved with updated baselines.

Read-after-assignment flow analysis remains unchanged: a subsequent read can still report TS2454 after an assertion-wrapped assignment.

Validation

I manually ran the following focused tests from the repository root on macOS ARM64. All passed:

GOWORK=off go -C tsc test -mod=readonly ./internal/testrunner \
  -run 'TestLocal/(usedBeforeAssignedTypeAssertion|classNameReferencesInStaticElements|assertedReadonlyParameterPropertyAssignment|assertedGenericPartialIndexedAssignment)' -count=1

The standalone reproduction reported TS2454 and exited 2 before the fix. I reran it with a compiler built from 4a2cd92c47d744d003a81503982430914c677b0d: no diagnostics, exit 0.

AI assistance: Copilot helped generate the regression tests. I reviewed the changes and will handle any review feedback or revisions myself.

Copilot AI balanced review requested due to automatic review settings October 26, 2026 05:55
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Oct 26, 2026
@typescript-automation typescript-automation Bot added For Backlog Bug PRs that fix a backlog bug labels Oct 26, 2026

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Backlog Bug PRs that fix a backlog bug

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

"used before being assigned" fires on LHS inside parens/type assertion

2 participants