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

.d.ts typescript definition doesn't match js with proto3 optional fields #1072

Closed
mattnathan opened this issue Apr 20, 2021 · 2 comments · Fixed by #1184
Closed

.d.ts typescript definition doesn't match js with proto3 optional fields #1072

mattnathan opened this issue Apr 20, 2021 · 2 comments · Fixed by #1184

Comments

@mattnathan
Copy link
Contributor

mattnathan commented Apr 20, 2021

Given a proto file like

syntax = "proto3";

message MyMessage {
  optional float my_prop = 1;
}

Running the generator with options --js_out=import_style=commonjs,binary:. --grpc-web_out=import_style=commonjs+dts,mode=grpcwebtext:. the generated _pb.js file correctly has the get, set, has, and clear methods for interacting with the property. The _pb.d.ts file, however, describes the property using the fallback enum representation with get, set, and a MyPropCase enum for describing the _NOT_SET and set semantics.

While I understand that this is technically correct for a language generator to describe the proto message in this way (that's how backwards compatibility is supported), this doesn't really work in this case as the .d.ts file is supposed to describe the .js file.

Anyway, sorry if this is reported elsewhere, I couldn't find anything when searching.

@mattnathan
Copy link
Contributor Author

I have created a PR.

I'm no C/C++ developer so I hope the change is correct. I'm also a little lost for how to build and/or test the change.
I want to help, but will need pointers from someone who knows this project a little more that I do.

@sampajano
Copy link
Collaborator

sampajano commented Jan 27, 2022

@mattnathan Thanks so much again for raising the issue and creating a PR! It's a great issue to fix! 😃😃

sampajano pushed a commit that referenced this issue Jan 28, 2022
…#1184)

* Correctly support proto3 optional fields in commonjs+dts .d.ts output

Fixes #1072

* Use has_optional_keyword instead of is_optional

* Improve the readability of the condition guarding hasXxx .d.ts field generation.
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.

2 participants