Skip to content

Conversation

xazukx
Copy link

@xazukx xazukx commented Jun 10, 2025

Goal

Add native typescript enums with string values. Integer values are not supported.
I have been using this in a very large codebase with many enum types (simple enums, tuple children, struct children, etc) for a few months with no problems. I've decided to open this PR and bring it to the world.

Changes

I added the attribute #[ts(use_ts_enum)] in order to turn a simple rust enum into a typescript enum. Case renaming still works except kebab renaming, because the name of the enum variant must be a valid typescript identifier. Proper warnings and errors are issued if invalid attributes are used alongside use_ts_enum on the same enum.
Inlining an enum in a struct switches back to using union types.

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.

@stunningpixels
Copy link

This is much needed for many production use-cases. Would be great to see this merged.

@fbartho
Copy link

fbartho commented Aug 30, 2025

I too would find enums super helpful in my codebase! (I came to this PR to see how I could help!)

@NyxCode
Copy link
Collaborator

NyxCode commented Sep 12, 2025

Hey, thanks for the PR! Sorry that it took so long for me to actually take a look at it.
@gustavo-shigueo has implemented some improvements of your PR in #425, supporting integer discriminants and all inflections. So I think it make sense to continue work on this feature over there.
Again, thanks for getting this work started!

Edit by @gustavo-shigueo: fix user name

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.

4 participants