-
Notifications
You must be signed in to change notification settings - Fork 24
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
ESP Enum encoding breaks TypeScript? #34
Comments
FWIW, my current workaround is:
|
I need some clarification, are you using Endpoints for gRPC with transcoding? I assume you are using gRPC backend and transcoding, then the JSON mapping for proto3 is defined in protobuf: https://developers.google.com/protocol-buffers/docs/proto3#json
Do you have an example for this? |
I'm using gRPC Endpoints with transcoding provided by the ESP. The mapping you linked is problematic because TypeScript string enums were only introduced in version 2.4. @angular/angular-cli currently does not support TypeScript versions newer than 2.3.4. It's desirable to keep client-side and server-side enums closely aligned, yet the ESP forces client-side enums to be strings. |
From my own experiments with a local ESP and gRPC backend, it seems proto defined enums such as
...are received on the (web) client as enum names (strings) and not enum values:
I could change my client-side TypeScript enums from:
to
This works when receiving an enum from the gRPC backend (via the ESP). However, the same enum cannot then be used when the (web) client makes a request (the numeric value must be used).
This appears to be WIA since in ProtoToJson the message is serialized using SerializeToString
std::string binary = message.SerializeAsString();
I'm unsure why my JavaScript client doesn't balk at this, regardless, the result is, an enum with string values.
console.log(myEnumInstance)
yields:["OBJECT", "STRING", "BOOLEAN"]
This means while the underlying type is a string (thanks to ESP), any comparison causes a compilation error:
...yields:
Yet the following causes a compilation error:
So, I'm stuck with string values in my enum that I can't use. Again, IDK how it is the web client's OK with this. Perhaps there's some coercion by the HTTP module in Angular?
The text was updated successfully, but these errors were encountered: