Skip to content

fix(import_elision): handle tuple type elements without panicking#272

Open
ashley-hunter wants to merge 2 commits into
voidzero-dev:mainfrom
ashley-hunter:fix/tuple-type-element-panic
Open

fix(import_elision): handle tuple type elements without panicking#272
ashley-hunter wants to merge 2 commits into
voidzero-dev:mainfrom
ashley-hunter:fix/tuple-type-element-panic

Conversation

@ashley-hunter
Copy link
Copy Markdown
Contributor

Summary

  • Fixes a panic in collect_computed_keys_from_ts_type when a TSTupleType contained TSOptionalType (T?) or TSRestType (...T[]) elements — to_ts_type() called unwrap() on None for these variants
  • Replaces the panicking to_ts_type() call with the safe as_ts_type() and adds explicit branches for TSOptionalType and TSRestType
  • Fixes an incomplete handling of TSNamedTupleMember: it is an inherited TSType variant (not a named TSTupleElement variant), so it arrives in collect_computed_keys_from_ts_type via the as_ts_type() path — the match arm added for it in the tuple loop was unreachable; adds a TSType::TSNamedTupleMember case to collect_computed_keys_from_ts_type so computed property keys inside named tuple member element types are correctly preserved

Test plan

  • test_computed_key_in_optional_tuple_element_preserved[myKey] inside a T? element
  • test_computed_key_in_rest_tuple_element_preserved[myKey] inside a ...T[] rest element
  • test_computed_key_in_named_tuple_member_preserved[myKey] inside a label: T named member
  • test_tuple_with_mixed_element_kinds_no_panic — mixed optional/rest/named tuple, confirms no panic
  • All 46 existing import_elision unit tests pass

🤖 Generated with Claude Code

ashley-hunter and others added 2 commits May 13, 2026 17:09
`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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant