Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
pkwarren opened this issue Apr 2, 2021 · 0 comments · Fixed by #272
Closed

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

pkwarren opened this issue Apr 2, 2021 · 0 comments · Fixed by #272

Comments

@pkwarren
Copy link
Contributor

pkwarren commented Apr 2, 2021

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

MarcusLongmuir pushed a commit that referenced this issue Apr 26, 2021
Update the typescript generator to add a suffix '$' to methods which
conflict on the Message base class
('getExtension'/'setExtension'/'getJsPbMessageId'/'setJsPbMessageId').
This will keep the typescript definitions in sync with the generated JS
code from the protoc compiler.

Fixes #271.
MarcusLongmuir added a commit that referenced this issue Apr 26, 2021
* Fix get/set conflicting method names.

Update the typescript generator to add a suffix '$' to methods which
conflict on the Message base class
('getExtension'/'setExtension'/'getJsPbMessageId'/'setJsPbMessageId').
This will keep the typescript definitions in sync with the generated JS
code from the protoc compiler.

Fixes #271.

* Presence checks with conflicting namess

* Fix clear method name.

Co-authored-by: Marcus Longmuir <marcus.longmuir@improbable.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant