improbable-eng / ts-protoc-gen

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

Incorrect get/set methods generated for 'extension'/'js_pb_message_id' fields. #271

Closed pkwarren closed 3 years ago

pkwarren commented 3 years ago

There are methods defined on the base protobuf Message class which conflict with the default getter/setter methods. The protoc compiler works around this by adding a '$' suffix to the methods so there are no conflicts, however ts-protoc-gen doesn't use the same algorithm.

Reference: https://github.com/protocolbuffers/protobuf/blob/97cb3a862f132c6ab98e240be11990b89f7d5467/src/google/protobuf/compiler/js/js_generator.cc#L528-L531

Versions of relevant software used 0.14.0

What happened Typescript types for field named 'extension' are incorrect. The base message class has methods 'getExtension' and 'setExtension' and so the protoc compiler adds a '$' suffix on the getter/setter method names to not conflict.

What you expected to happen Types to match the generated JS code from protoc.

How to reproduce it (as minimally and precisely as possible): Create a simple message:

message GetterNameConflictMessage {
    string extension = 1;
    bytes js_pb_message_id = 2;
}

Run the protoc compiler and ts-protoc-gen. Notice that the typescript types have conflicting methods 'getExtension', 'setExtension', 'getJsPbMessageId', 'setJsPbMessageId'

Full logs to relevant components

n/a

Anything else we need to know

n/a