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

Support for proto3 optional fields #263

Closed
stof opened this issue Jan 22, 2021 · 6 comments · Fixed by #275
Closed

Support for proto3 optional fields #263

stof opened this issue Jan 22, 2021 · 6 comments · Fixed by #275

Comments

@stof
Copy link

stof commented Jan 22, 2021

This is resurrecting #227 which has been closed without any feedback.

protoc 3.12+ has experimental support for optional in proto3 (see https://github.com/protocolbuffers/protobuf/blob/master/docs/implementing_proto3_presence.md). Of all the code generators I checks, this one is the only one which does not support it.
As its goal is to generate declaration files for the protoc JS output which does support that feature, it would be great if it could be supported.

@stof
Copy link
Author

stof commented Jan 22, 2021

Looking at the code, I think that supporting that could be as easy as updating the implementation of hasFieldPresence in

function hasFieldPresence(field: FieldDescriptorProto, fileDescriptor: FileDescriptorProto): boolean {
to check for the new option (and marking the feature as supported in the CodeGeneratorResponse of course).

@Skyedra
Copy link

Skyedra commented Mar 19, 2021

This would be a very useful feature for users who are holding on to proto2 because of optional support.

@huan
Copy link

huan commented Mar 24, 2021

I definitely need this feature. Now it's a blocker in my project wechaty/grpc#109

@awbraunstein
Copy link
Contributor

I'm going to take on fixing this. DefinitelyTyped/DefinitelyTyped#52380 is a requirement to fix this in this repo.

@MarcusLongmuir
Copy link
Contributor

Thanks for picking this up @awbraunstein. Apologies for the delay on acking this.

I made progress on this branch, but got sidetracked before getting to address the types that you've contributed to DefinitelyTyped.

Feel free to take from that branch (if you don't already have it functioning) and raise a PR once the types are merged. Thanks!

@awbraunstein
Copy link
Contributor

@MarcusLongmuir Thanks for the pointer to the branch. I have something that looks very similar locally, though I haven't written any tests yet, so I may steal yours.

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.

5 participants