-
Notifications
You must be signed in to change notification settings - Fork 648
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
grpc-tools: add grpc_js param to grpc_out #1380
Conversation
This is a minor change to use the pure JavaScript gRPC Client `@grpc/grpc-js` instead of the (now deprecated `grpc` node package).
Hi Richard, you mentioned
May I ask what tools you're using to generate TS types? I tried |
Never mind. I saw your PR: improbable-eng/ts-protoc-gen#236 Hope it gets merged soon. |
@laike9m i'm not sure if the authors of that package are keen to improve it as i've had zero feedback. i've been meaning to have a look at the new typescript generator offered by @murgatroid99, and i would suggest to consider using that package instead. see: #528 (comment) example of how it can be used: grpc-node/packages/grpc-js/generateTypes.sh Lines 18 to 20 in 095a3b4
|
Great, let me try that out. Thanks for the pointer. |
I gave it a try, but somehow it confused me. Not sure if I'm doing anything wrong: |
This is a minor change to use the pure JavaScript gRPC Client
@grpc/grpc-js
instead of the (now deprecated)grpc
node package when generating javascript files using the proto compiler. This change is very similar to thegenerate_package_definition
param.Reasoning:
I understand that it's recommended to use
@grpc/proto-loader
to the load protos files.I have some hesitation to adopt this approach, as when using TypeScript, I have to typecast using type assertions to type the grpc client as a
ServiceClientConstructor
, for example:My client is then defined as:
grpc-node/packages/grpc-js/src/make-client.ts
Lines 83 to 85 in 4ec023c
..and I loose all the benefits of (for example) IntelliSense in my IDE. I also don't know if my method calls are correct until I compile the TypeScript to JS. It's not a great developer experience.
The change i'm proposing is to support "grpc_js" within the proto compiler. This will allow me to generate static javascript files that require
@grpc/grpc-js
instead ofgrpc
, and will allow existing tools to then generate types from those files.I also feel this a good change to support existing projects & tooling that would like to switch over to using
@grpc/grpc-js
. It will allow for better adoption as the required changes in the consuming projects are minimal.