Skip to content

Check #[ts(flatten)] at compile time instead of panicking during export#480

Draft
gustavo-shigueo wants to merge 4 commits intomainfrom
flatten_compile_time_error
Draft

Check #[ts(flatten)] at compile time instead of panicking during export#480
gustavo-shigueo wants to merge 4 commits intomainfrom
flatten_compile_time_error

Conversation

@gustavo-shigueo
Copy link
Collaborator

@gustavo-shigueo gustavo-shigueo commented Feb 12, 2026

Goal

Hey @NyxCode, since #[ts(flatten)] has been getting a lot of attention lately, I thought it might be worth taking a look at checking if using it in any given field is legal at compile time instead of assuming it is and panicking at runtime if the assumption was wrong.

Now, this PR is a draft for a few reasons:

  • I don't fully understand Dependencies enough to be even mildly confident that I did any of this correctly
  • This is a very major change that should be studied carefully, this is just a suggestion with a POC attached, not a feature request or anything
  • The implementation is probably severely wrong lol

Changes

Added a Flattenable trait to store the inline_flattened method. All Flattenables must implement TS for obvious reasons, but several types implement TS without implementing Flattenable, e.g.: String, i32, bool etc. This means that, when #[ts(flatten)] emits <T as Flattenable>::inline_flattened(), the user gets a compiler error if their type is cannot be flattened

Checklist

  • I have followed the steps listed in the Contributing guide.
  • If necessary, I have added documentation related to the changes made.
  • I have added or updated the tests related to the changes made.

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