-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
TypeScript generation to support node-grpc #1017
Comments
Note that Promises are not really allowed to have multiple values (they officially end after one value). But RXJS Observables seem to be a good fit for multiple values... they definitely are designed for streams in this sense. - Just a note that you might find some promise libraries that do technically work after the first response, but are not really supposed to. |
There's been quite a discussion at grpc/grpc-node#528 about this recently. |
TL;DR: a dedicated support is needed from protobuf.js, in particular we need better understanding and type definitions for the format that The type definitions for those two pretty much allow anything, while it practice there are concrete requirements to the input, and the output has a particular shape. And, what's interesting, the message interfaces do not fit as valid descriptions for the objects passed to |
I was able to successfully create a server in TypeScript with protobufjs along with a few additions. https://stackoverflow.com/a/64778825/242042 The protobufjs generates the request and response callbacks properly the most part. However, I had to create the "service" types as follows The interface for the service, I think this can be generated by a tool
These are needed to expose
I can force a type check when adding the service as follows
|
I've found a way of doing a slightly cleaner typescript and made some alterations to pretend I am crazy enough to put more than one This is the common interfaces, maybe it should be part of GRPC itself. I reduced it to a single class
And here are my application specific code which I think can be generated with a tool.
Then:
Then the server and implementations:
|
I'm trying to use protobuf.js with grpc-node native core, and want to have a proper TypeScript definitions.
I have already mentioned this at #1007, but I'm really struggling with incompatibilities of the generated TypeScript types and the grpc implementation. Decided it's worth a separate issue here.
So, the problem is, TypeScript generated code does not reflect the existence of the streams in the rpc definition.
Example:
(comments and some code parts are removed for clarity)
As seen from the example, function signatures in TypeScript are the same, despite them being different in the protobuf definition.
I'd like to discuss and, probably, correctly implement the extensive support for protobuf format and compatibility with grpc-node.
This is a starting point. I'll publish a sample repo soon with the examples so that we have something to play with.
The text was updated successfully, but these errors were encountered: