[JavaScript] Getters returning nulls instead of default values for primitives
What language does this apply to?
JavaScript
Describe the problem you are trying to solve.
Currently, all generated getters for primitives in _pb.js files call to jspb.Message.getFieldWithDefault and there seem to be no way to tell generator to simply call jspb.Message.getField instead.
This is particularly problematic when using proto2 syntax with required/optional numeric fields. If an optional field is not set, it will default to "0".
Describe the solution you'd like
Ideally there would be an option passed to the js_out parameter of protoc where we could say whether or not to use defaults.
Describe alternatives you've considered
One could potentially leverage hasMyField() to determine if the field has been set or not, but it would make the mapping layer between proto and internal app model even more verbose, as this would need to be done on all optional fields, which we have quite a few.
This problem has been fixed on the plugin we are maintaining for typescript. https://github.com/thesayyn/protoc-gen-ts
This problem has been fixed on the plugin we were maintaining for typescript. https://github.com/thesayyn/protoc-gen-ts
Why'd you put that in the past tense? Are you no longer maintaining it? I am just in the process of adopting protobufs for a JS project (and am already kind of regretting the decision), and your plugin is the one ray of light in the whole experience so far.
Why'd you put that in the past tense? Are you no longer maintaining it? I am just in the process of adopting protobufs for a JS project (and am already kind of regretting the decision), and your plugin is the one ray of light in the whole experience so far.
That’s a problem when you have English as a second language. My bad. it should have been are. Sorry about that
and No we are still maintaining it.
Our plan is to add alternate accessors that allow you to treat absence as undefined values.