You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Feature Request] Allow @unboxed on tagged variants #6547
There's a bug in the syntax right now that prevents you from doing this without prepending a dummy field, but this will be possible as soon as that bug is fixed:
Correct, so it's not the same type, although they're identical (but one is inline and one is not) which limits things a bit. But when it's readonly, and especially in the context of GraphQL unions etc, I think it might be enough.
The record definition spread is useful for forcing not to reuse value type in ReScript. But when interacting with structurally typed language, I often want the opposite.
In the example (and its imaginable use case), I need to be able to spread user data into the actual payload. It would be much more convenient if this could be achieved without copying all fields.
I'd like to mention this (#5207 (comment)) from the original request. We can say the current behavior is a kind of hybrid (internal tag or adjacent tag), but that is chosen by the compiler.
One way to make this possible without @unboxed is to give the user even more control over the runtime representation.
For example, @tag.internal("name") and @tag.adjacent("name")
`
Reacted by Jeong-Sik Yun, Jaeho Lee (Jay), Paul Tsnobiladzé and Stephanos Komnenos
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Activity
zth commentedon Jan 3, 2024
You can use an inline record to achieve that runtime representation.
cometkim commentedon Jan 3, 2024
I'm building a code generator, so I just wanna refer an existing type by its name. Is it not the common case?
zth commentedon Jan 3, 2024
There's a bug in the syntax right now that prevents you from doing this without prepending a dummy field, but this will be possible as soon as that bug is fixed:
This doesn't let you go back to the
usertype etc easily though since you can't coerce an inline record. But it does solve the problem.cometkim commentedon Jan 3, 2024
It does only guarantee the output structure is the same, and it does not point to the same type(name). Do I understand correctly?
zth commentedon Jan 3, 2024
Correct, so it's not the same type, although they're identical (but one is inline and one is not) which limits things a bit. But when it's readonly, and especially in the context of GraphQL unions etc, I think it might be enough.
cometkim commentedon Jan 3, 2024
The record definition spread is useful for forcing not to reuse value type in ReScript. But when interacting with structurally typed language, I often want the opposite.
In the example (and its imaginable use case), I need to be able to spread
userdata into the actual payload. It would be much more convenient if this could be achieved without copying all fields.I'd like to mention this (#5207 (comment)) from the original request. We can say the current behavior is a kind of hybrid (internal tag or adjacent tag), but that is chosen by the compiler.
One way to make this possible without
@unboxedis to give the user even more control over the runtime representation.For example,
@tag.internal("name")and@tag.adjacent("name")`
github-actions commentedon Dec 29, 2024
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
stephanoskomnenos commentedon May 27, 2025
This feature is useful for creating js bindings.
github-actions commentedon May 23, 2026
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.