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

Provide string enum option #26

Open
rurutia opened this issue Feb 16, 2019 · 0 comments
Open

Provide string enum option #26

rurutia opened this issue Feb 16, 2019 · 0 comments

Comments

@rurutia
Copy link

rurutia commented Feb 16, 2019

Avro enums are only compiled to numeric enums

export enum colorTypes {
    red,
    blue,
    green,
}

It does not work for our scenario when having java consumer expecting string value from the same schema. It needs to be compiled to string enums like

export enum colorTypes {
    red = "red",
    blue = "blue",
    green = "green",
}

actually, I think by default typescript enum should always be constant-initialized with a string literal fpor avro serde as suggested by https://www.typescriptlang.org/docs/handbook/enums.html

String enums have the benefit that they “serialize” well. In other words, if you were debugging and had to read the runtime value of a numeric enum, the value is often opaque - it doesn’t convey any useful meaning on its own (though reverse mapping can often help), string enums allow you to give a meaningful and readable value when your code runs, independent of the name of the enum member itself.

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

1 participant