improbable-eng / ts-protoc-gen

Protocol Buffers Compiler (protoc) plugin for TypeScript and gRPC-Web.
Apache License 2.0
1.36k stars 173 forks source link

Trailing underscore, toObject produces object that does not conform to AsObject #309

Open robdodson opened 2 years ago

robdodson commented 2 years ago

Versions of relevant software used

What happened I think this may be related to https://github.com/improbable-eng/ts-protoc-gen/issues/182

We're using Goa to generate our .proto files. If you name a field message in Goa, it will rename it to message_ in the .proto.

note.proto

message Note {
    string message_ = 1;
}

If you then process this proto using ts-protoc-gen, the toObject method does not conform to AsObject:

note.d.ts

export namespace Note {
  export type AsObject = {
    message_: string,
  }
}

_notepb.js

proto.voc_admin.Note.toObject = function(includeInstance, msg) {
  var f, obj = {
    message: jspb.Message.getFieldWithDefault(msg, 1, "")
  };

  // ...
};

What you expected to happen The property should be named message_ in the object returned from note_pb.js.

How to reproduce it (as minimally and precisely as possible): Create a field with a trailing underscore in your .proto file.