Support of string-based enums
See original GitHub issueI know this kind of a limitation of proto
protocol, but would be good to have the ability to have string-based enums in TS.
enum EmploymentStatus {
unemployed = 0;
employed = 1;
student = 2;
retired = 3;
}
it intended to be in the TS:
enum EmploymentStatus = {
unemployed = 'unemployed';
employed = 'employed';
student = 'student';
retired = 'retired';
}
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
TypeScript string enums, and when and how to use them
No matter how much you know about TypeScript enums, this guide covers all the best practices for using string-based enums in production.
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 >String Enums in C#: Everything You Need to Know
Since C# doesn't support enum with string value, in this blog post, we'll look at alternatives and examples that you can use in...
Read more >typescript - Create an enum with string values - Stack Overflow
Enums in TypeScript are number based. You can use a class with static members though: class E { static hello = "hello" ...
Read more >String-based enums · Issue #2849 · dotnet/csharplang - GitHub
The primary value of string-based enums is that they are extensible without changing the type definition: OSPlatform platform = (OSPlatform)" ...
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
also, using oneof fileds could be an option.
since one of fields can present one at a time, this would act like an enum and we wouldn’t have to worry about wire format or interoperability as this is a normal way of using the language.
@thesayyn Here it says the ENUM specification: https://developers.google.com/protocol-buffers/docs/proto3#json It must be a string, not an integer. If you use Protobuf with dart, it will serialize enums as strings, and this plugin will not understand that.