improbable-eng / ts-protoc-gen

Protocol Buffers Compiler (protoc) plugin for TypeScript and gRPC-Web.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

robdodson opened this issue · comments

Versions of relevant software used

  • libprotoc 3.19.4
  • ts-protoc-gen 0.15.0

What happened
I think this may be related to #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,
  }
}

note_pb.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.