1 | initial version |
To make protobuf.js generate string values for enums instead of integers, you can use the string
option when defining the enum field in the protobuf schema:
enum MyEnum {
option allow_alias = true;
option (protobufjs.enum_value_string) = true; // enable string values
VALUE_ONE = 0 [(protobufjs.value) = "enum-value-one"]; // set string value
VALUE_TWO = 1 [(protobufjs.value) = "enum-value-two"]; // set string value
}
Here, the (protobufjs.enum_value_string) = true
option enables string values for the enum, and the (protobufjs.value)
option allows you to set a custom string value for each enum value.
When you generate code from this schema using protobuf.js, the generated TypeScript/JavaScript code will have string values for the enum instead of integers:
enum MyEnum {
VALUE_ONE = "enum-value-one",
VALUE_TWO = "enum-value-two",
}