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

Add support for externally tagged unions #10

Closed
sphinxc0re opened this issue May 2, 2021 · 2 comments
Closed

Add support for externally tagged unions #10

sphinxc0re opened this issue May 2, 2021 · 2 comments

Comments

@sphinxc0re
Copy link

Externally tagged unions it the default for serde enums in e.g. JSON.

An enum like this:

pub enum Field {
    Floor,
    Wall,
    Portal { id: usize, target: MapAddress },
    Exit,
    Special { id: usize },
}

would convert to this:

export type Field =
  | "Floor"
  | "Wall"
  | {
      Portal: {
        id: number;
        target: MapAddress;
      };
    }
  | "Exit"
  | {
      Special: {
        id: number;
      };
    };

It looks kinda ugly but it's very useful to me and it's the serde default.

@NyxCode
Copy link
Collaborator

NyxCode commented Nov 1, 2021

I have thought about this, and I do agree!
The default serde behavious looks disgusting, but we need to be compatible to it.
I've created this new branch to make this the default behaviour.

@NyxCode
Copy link
Collaborator

NyxCode commented Nov 8, 2021

closing in favor of #38

@NyxCode NyxCode closed this as completed Nov 8, 2021
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

No branches or pull requests

2 participants