Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support custom enum discriminator #70

Merged
merged 5 commits into from Jul 25, 2023

Conversation

kevinresol
Copy link
Collaborator

Emit a field under the defined name, with value being the enum constructor name. For nicer consumption in native js code (without relying on the ugly _hx_index field).

Example:
-D genes.enum_discriminator=$kind

Would emit haxe.ds.Option.None as {_hx_index:0, $kind:"None"} and haxe.ds.Option.Some(42) as {_hx_index:1, $kind:"Some", value:42} (not exact but you get the idea)

So in native JS/TS code one can consume the value with:

switch (option.$kind) {
  case "None":
  case "Some": option.value // type-safe access
}

@benmerckx
Copy link
Owner

We'll want to add this to TS definitions as well

@benmerckx benmerckx merged commit b860527 into benmerckx:master Jul 25, 2023
4 checks passed
@skial skial mentioned this pull request Jul 26, 2023
1 task
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.

None yet

2 participants