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

@grpc/grpc-js Server addService(..) function and @ts-ignore #24

Open
ghost opened this issue Oct 15, 2022 · 1 comment
Open

@grpc/grpc-js Server addService(..) function and @ts-ignore #24

ghost opened this issue Oct 15, 2022 · 1 comment

Comments

@ghost
Copy link

ghost commented Oct 15, 2022

Your demo is fantastic.

The tldr; is - it helped me resolve two issues I couldn't figure out:

  1. grpc.Server.addService(..) would not transpile no matter what I gave it in my typescript app - so I ignored that statement as you did
  2. no matter what arguments I gave to "protoc" - it failed to generate the correct output (exp: it would reference the "window" global from browsers) - so I switch to grpc_tools_node_protoc as you did

grpc.Server.addService(..)

The following is just a more thorough account of my findings and why I wasn't able to resolve my issues without just doing what you did.

Something I've been banging my head against the wall is the Server addService(..) function - i.e. this:

grpc.Server.addService(service: ServiceDefinition, implementation: UntypedServiceImplementation)

In your code - you did the following:

    // @ts-ignore
    server.addService(SongsService, new SongsServer());

Without the ts-ignore - tsc doesn't succeed in the transpile and I can't understand why.

I've found number reports/issues related to this bit of code - but up until now I haven't been able to find a way to work-around the issue. The most relevant post I found was this:
grpc/grpc-node#1766

But, that issue was reported over a year ago and apparently was fixed in grpc version 1.24.11.

I found some other issues that are related to this - exp:
agreatfool/grpc_tools_node_protoc_ts#79

But, again these posts are over a year old - so I must be missing something else.

Anyway, your sample/tutorial helped me overcome that issue - i.e. disabling the typescript check on that statement.

protoc vs grpc_tools_node_protoc

No matter what arguments I gave to protoc - it

protoc \
    --plugin="protoc-gen-ts=${PROTOC_GEN_TS_PATH}" \
    --js_out="import_style=commonjs,binary:${TS_OUT_DIR}" \
    --ts_out="service=grpc-node,mode=grpc-js:${TS_OUT_DIR}" \
    -I="./proto" \
    ./proto/com/generic/v1/services/*.proto

the generated code would create a statement like the following in the code:

var global = (function() { return this || window || global || self || Function('return this')(); }).call(null);

You can read about this issue here:
protocolbuffers/protobuf-javascript#8

I tried using a variety of different versions of various tools, plugins, etc to no avail.

@reececomo
Copy link

Without the ts-ignore - tsc doesn't succeed in the transpile and I can't understand why.

👍 same issue

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

No branches or pull requests

1 participant