Repository navigation
Revert the checked-cast fallback (#1561); keep the optional-chain fix - #1601
Merged
Merged
Conversation
`a?.b.c` on an `any` value answered undefined when `a` was present and `a.b` undefined: every later step of the chain read optionally. Node short-circuits only on the guarded receiver and throws reading `.c`. An `any` receiver now makes the tail an optional chain like a dyn one, and inside the chain's guarded body the consumed `?.` no longer marks the later dynamic reads optional. (Kept from #1561, whose checked-cast fallback is reverted.) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully 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.
Reverts #1561 (6bb2711) and keeps its one unrelated fix.
Why
scriptc's premise is that types don't lie. #1561 made a checked cast whose value does not fit its type (
JSON.parse(text) as T,const x: T = anyValue) continue in a dynamic copy of the code after it, so a program could keep running on data that contradicts its own types. That was a misdirection: a mismatch should stay aTypeErrornaming the path, and programs and test fixtures should declare types that match their data. This restores the checked-cast behavior and its documentation (the runtime type checks section, the limitations page and--tier) to what they were before #1561.What stays
a?.b.con ananyvalue short-circuits only on the guarded step: it isundefinedwhenais nullish and throws whenais present buta.bis undefined, as in Node (before #1561 it answeredundefined). That piece is re-applied as its own commit with a new corpus program,optional-chain-any-tail.ts, identical to Node in both lanes.corpus/1544-dyn-json-reads.tskeeps its #1561 binary.Nothing merged after #1561 used it: no references to
scr_dyn_check_recover,checked-fallback.ts, thecheckedCast.*builtins or the fallback JSON helper remain.Validation
pnpm test:ts7 --baselines-only, and the self-host IR build (no diagnostics).dyncheck,json-callbacks,native-class-array-boundaries,discriminated-json,json-schema-parse-emission, diagnostics, npm-static and ts7 order parity: 479 passed.6412-any-valued-dictionaries,caught-system-error-fields,json-typed-parse-index-signatures).1544-dyn-json-readsincluded, is identical. Compile time: bench geomean −0.23%, self-hosted compiler +0.97% (within tolerance).🤖 Generated with Claude Code