enums as string value
See original GitHub issueHello,
ts-proto
offers the options --ts_proto_opt=stringEnums=true
which allows for generated enum types to be string-based instead of int-based.
This is useful if you want “only types” and are using a gRPC REST Gateway configured to serialize enums as strings.
Are you willing to support this? It will be very useful in a twirp and gPRC gateway setting
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (8 by maintainers)
Top Results From Across the Web
Using Enum values as String literals - java - Stack Overflow
Option One: use the built-in name() on an enum. This is perfectly fine if you don't need any special naming format. String name...
Read more >String Enums in C#: Everything You Need to Know
An enumeration type is a value type that has a set of named constants. To declare an enumeration type, use the enum keyword...
Read more >Convert Enum To String In C# - C# Corner
We can convert an enum to string by calling the ToString() method of an Enum. The following code example shows how to convert...
Read more >Handbook - Enums - TypeScript
String enums allow you to give a meaningful and readable value when your code runs, independent of the name of the enum member...
Read more >Enum.ToString Method (System) - Microsoft Learn
Converts the string representation of the name or numeric value of one or more enumerated constants to an equivalent enumerated object. The return...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Give it a try, this already works 😁
The canonical mapping for a protobuf enum is string, and parsers must accept both enum names and integer values.
The canonical mapping deals with edge cases like numeric map keys, infinite numbers, etc. The documentation is sparse, but the conformance tests are not (protobuf-ts passes them). You can be pretty sure that you’ll have perfect JSON interoperability.
@timostamm I gave more and more thoughts around this.
I think you are 100% right here, it all boils down to how enums works in protobuf.
For now I’ll accept the fact that they are annoying 😄 as a workaround I’ve nested my enum to prevent collisions: