Broken typescript exports after moving to @grpc/grpc-js
See original GitHub issueHey,
After updating to @grpc/grpc-js
all the exports got changed from export BookService
https://github.com/grpc/grpc-node/blob/a5cc154c8e49cf68691880cbddf33456fbbd306a/packages/grpc-tools/src/node_generator.cc#L190 to export['com.book.BookService']
.
https://github.com/grpc/grpc-node/blob/a5cc154c8e49cf68691880cbddf33456fbbd306a/packages/grpc-tools/src/node_generator.cc#L188
What is the point of such change? Now it’s not possible to generate proper typescript definitions for such exports.
// grpc
import { BookServiceClient } from "./proto/book_grpc_pb";
const client = new BookServiceClient("127.0.0.1:50051", grpc.credentials.createInsecure());
// changed to
// grpc-js
import * as bookGrpcPb from "./proto/book_grpc_pb";
// @ts-ignore
const BookServiceClient = grpc.makeClientConstructor(bookGrpcPb["com.book.BookService"], "BookService");
So now such export is not valid for Typescript and you have to write // @ts-ignore
.
Why was removed export of the BookServiceClient
? or at least BookService
?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:5 (1 by maintainers)
Top Results From Across the Web
grpc/grpc-js
Start using @grpc/grpc-js in your project by running `npm i ... TypeScript icon, indicating that this package has built-in type declarations.
Read more >Top 5 @grpc/grpc-js Code Examples
Learn more about how to use @grpc/grpc-js, based on @grpc/grpc-js code examples ... lab = exports.lab = Lab.script(); const { describe, it, before,...
Read more >does not provide an export named when using vite in grpc- ...
I'm trying to use vite. I've some JavaScript-generated files for GRPC communication; alongside each file, there is a declarative file ...
Read more >gRPC service in Node.js: Tutorial, Examples and Best ...
JavaScript ; How Nodejs works; REST; API; Client to server communication. We will need the following tools installed in our machine: Nodejs ...
Read more >What is gRPC ? How to implement gRPC in Node.js
gRPC built on top of Remote Procedure Call and Http/2 with Protocol Buffers. ... and transfer the data over the network. it is...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
That second line you linked is in the
generate_package_definition
branch, which is triggered by using thegenerate_package_definition
code generation option. That option makes the generated file export an object that is intended to be loaded usinggrpc.loadPackageDefinition
. You could then apply a TypeScript type to the resulting object.However, using that option is not the only way to generate code for use with the
grpc-js
library. You could also use thegrpc_js
code generation option instead. That will generate code very similar to the code generated without any options, except that it will import@grpc/grpc-js
instead ofgrpc
.@ikibalnyi OK, thanks. Then I could give the upgrade warning. Next version of ts grpc tool have to be upgraded with grpc-tools version over 1.9.0.