fix(import_elision): handle tuple type elements without panicking#272
Open
ashley-hunter wants to merge 2 commits into
Open
fix(import_elision): handle tuple type elements without panicking#272ashley-hunter wants to merge 2 commits into
ashley-hunter wants to merge 2 commits into
Conversation
`TSTupleElement::to_ts_type()` panicked when the element was `TSOptionalType` or `TSRestType` (discriminants outside the inherited `TSType` range). Switch to `as_ts_type()` for safety and add explicit branches for those two variants. Also adds `TSType::TSNamedTupleMember` handling in `collect_computed_keys_from_ts_type`: named tuple members are inherited `TSType` variants so they arrive there via `as_ts_type()`, not the match arm that was previously added for them (which was unreachable). Without this, computed property keys inside named tuple member element types were silently not traversed and their imports were incorrectly elided. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… arm TSNamedTupleMember is an inherited TSType variant so as_ts_type() always returns Some for it — the match arm added in the TSTupleType loop was dead code. Traversal is handled by the TSNamedTupleMember arm in collect_computed_keys_from_ts_type. Clean up the stale comment too. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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
collect_computed_keys_from_ts_typewhen aTSTupleTypecontainedTSOptionalType(T?) orTSRestType(...T[]) elements —to_ts_type()calledunwrap()onNonefor these variantsto_ts_type()call with the safeas_ts_type()and adds explicit branches forTSOptionalTypeandTSRestTypeTSNamedTupleMember: it is an inheritedTSTypevariant (not a namedTSTupleElementvariant), so it arrives incollect_computed_keys_from_ts_typevia theas_ts_type()path — the match arm added for it in the tuple loop was unreachable; adds aTSType::TSNamedTupleMembercase tocollect_computed_keys_from_ts_typeso computed property keys inside named tuple member element types are correctly preservedTest plan
test_computed_key_in_optional_tuple_element_preserved—[myKey]inside aT?elementtest_computed_key_in_rest_tuple_element_preserved—[myKey]inside a...T[]rest elementtest_computed_key_in_named_tuple_member_preserved—[myKey]inside alabel: Tnamed membertest_tuple_with_mixed_element_kinds_no_panic— mixed optional/rest/named tuple, confirms no panicimport_elisionunit tests pass🤖 Generated with Claude Code