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

Question: Use of Object Literals #235

Open
wtatum opened this issue Jun 15, 2020 · 9 comments
Open

Question: Use of Object Literals #235

wtatum opened this issue Jun 15, 2020 · 9 comments
Labels

Comments

@wtatum
Copy link

wtatum commented Jun 15, 2020

The generated types for messages are classes with a no-args constructor, and settings/getters for each property. In many cases (especially unary request/response operations) this feels really superfluous and adds a lot of cruft to code that could otherwise be inlined. As a new user of GRPC it's not clear to me whether this is an artifact of ts-protoc-gen or it's just representative of the underlying types created in JS.

This can be partially addressed using toObject() but that's only available one way. Am I missing something meant to make this easier?

@wtatum
Copy link
Author

wtatum commented Jun 15, 2020

I found someone asking basically the same question over on the grpc-node project, where they were told this behavior is determined by the protobuf project, not by any of the protoc plugins.
grpc/grpc-node#1378

Does that sound right?

@wtatum
Copy link
Author

wtatum commented Jun 15, 2020

Cross posted this to Google Groups forum for Protobuf

https://groups.google.com/forum/#!forum/protobuf

@grant
Copy link

grant commented Jul 7, 2020

I have the same issue. Seems like this project is being forked in some cases and isn't currently active?
Are PRs accepted?

@stale
Copy link

stale bot commented Oct 12, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Oct 12, 2020
@entropitor
Copy link

It seems that the tutorial uses the "optimal" JS api but if you compile the proto files, then you need to use the getters/setters:

E.g. see https://github.com/grpc/grpc/tree/v1.33.1/examples/node/dynamic_codegen (using normal objects) versus https://github.com/grpc/grpc/tree/v1.33.1/examples/node/static_codegen (using getters / setters)

@stale stale bot removed the wontfix label Oct 28, 2020
@entropitor
Copy link

If you want to use the former, you can use grpc/grpc-node#1474 to get TS definitions

@RobinKamps
Copy link

@entropitor i generated the TS definition with grpc/grpc-node#1474 .
Could you explain, how you use/incorporate the ts definitions with the generated ts code from ts-protoc-gen?

@entropitor
Copy link

You can follow the examples on the grpc website. But when using typescript you can e.g. type your functions/services using one of the types that is generated (just add a manually type annotation)

@stale
Copy link

stale bot commented Apr 17, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Apr 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants