-
Notifications
You must be signed in to change notification settings - Fork 349
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
Optional primitives #120
Comments
@rubennaatje / cc @philikon since we was asking about something similar for arrays. Yeah, we could extend the I guess part of my curiosity is that I think this optionalness makes creation easier but hurts (imo) reading. I.e. for a protobuf field like
Makes this snippet A easier because it can leave off const foo: FooMessage = { desc: "foo" }; However, it means that snippet B becomes harder because it might be undefined: const foo: FooMessage = { desc: "foo" };
const name = foo.name; // might be undefined Which would be fine, however if we were to decode const foo: FooMessage = FooMessage.decode(...someBytes...);
const name = foo.name; // will be empty string I.e. client code that reads Which, is not terrible, but is more idiosyncratic than I'd like. Fwiw what
I.e. it's bringing in the base options to that Also note that Well, all of this is me just rationalizing why I don't think I'd use the
This is a little surprising to me, in theory with protobuf the gRPC service shouldn't be able to tell if the (primitive) field was either "not sent on the wire" or "sent on the wire as a default value"? |
@stephenh thanks for the well explained answer. I get all your points. And especially the last bit was interesting for me. I don't know why at some point we thought we needed all optionals but now I've completely replaced our stuff with yours. And it works fine :) So thanks for your time and thanks for your work. |
@rubennaatje cool, thanks for the follow up. :-) Glad it worked out! |
Is there a way to make sure everything is optional?
We used to have our own interface generator from protos that did that but we're now opting for an open source one, that is the only issue however.
Reason is that we use an gRPC service that breaks when some values are used with some calls.
The text was updated successfully, but these errors were encountered: