Add exporting to native typescript enums with string values #418
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.
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 alongsideuse_ts_enum
on the same enum.Inlining an enum in a struct switches back to using union types.
Checklist