When I executed the toObject method on a message with a field marked optional, that field became the default value like 0 or "". I expect it would be undefined.
I guess it is because the third argument of getFieldWithDefault is not undefined.
Since proto3 currently support optional keyword, when optional is specified, I think it should be undefined if it is not given.
proto
syntax = "proto3";
package com.book;
message OptTest {
optional string name = 1;
}
generated toObject code
proto.com.book.OptTest.toObject = function(includeInstance, msg) {
var f, obj = {
name: jspb.Message.getFieldWithDefault(msg, 1, "")
};
if (includeInstance) {
obj.$jspbMessageInstance = msg;
}
return obj;
};
versions
$ npm list --depth=0 -g
/usr/local/lib
+-- google-protobuf@3.21.2
+-- grpc_tools_node_protoc_ts@5.3.3
`-- grpc-tools@1.12.4
When I executed the
toObjectmethod on a message with a field markedoptional, that field became the default value like0or"". I expect it would beundefined.I guess it is because the third argument of
getFieldWithDefaultis notundefined.Since proto3 currently support
optionalkeyword, whenoptionalis specified, I think it should beundefinedif it is not given.proto
generated
toObjectcodeversions