Hello.
Trying to migrate a project over to official grpc-web, but there are a few things blocking me and my team. I'd like to report my findings.
- The type definition in
grpc-web/index.d.ts is different from the one coming from actual npm package. The unaryCall method is missing in installed package NPM_CODE, but present in this repository grpc-web/index.d.ts.
-
The unaryCall definition in grpc-web/index.d.ts, does not follow THE IMPLEMENTATION. The last options argument is not present in the definition.
-
The generated output (both typescript and commonjs+dts) does not include this options argument in client_.unaryCall call, as visible HERE. This is quite important since the options argument carries abort signal.
-
There is a difference in generated output API and the docs. JS version has separated *ServiceClient and *ServicePromiseClient, TS output generates single *ServiceClient class with method overloads.
Proposition.
The above issues might get just fixed, which from first look at the source code doesn't look too complicated. Only the part with overloading might cause some problems in typescript generated function body, because of extra logic needed to figure out if the argument is callback function, or options object. However, there might be a way to overcome this complications, if there is a chance to change the generated API.
Could the generated API follow a little different approach, exposing separate methods for different call methods? Instead of separate client classes and/or method overloading, have a single class with methodNameUnary and methodNamePromise and methodNameRpc? One calling unaryCall other calling thenableCall, etc.
I believe this way would be more explicit and also might be a bit easier to maintain in the generator. I also think, this proposed change could be done in a non-breaking way, leaving current API as it is and just adding new explicit ones next to that.
👋
Hello.
Trying to migrate a project over to official grpc-web, but there are a few things blocking me and my team. I'd like to report my findings.
grpc-web/index.d.tsis different from the one coming from actual npm package. TheunaryCallmethod is missing in installed package NPM_CODE, but present in this repository grpc-web/index.d.ts.The
unaryCalldefinition in grpc-web/index.d.ts, does not follow THE IMPLEMENTATION. The lastoptionsargument is not present in the definition.The generated output (both typescript and commonjs+dts) does not include this
optionsargument inclient_.unaryCallcall, as visible HERE. This is quite important since theoptionsargument carries abort signal.There is a difference in generated output API and the docs. JS version has separated
*ServiceClientand*ServicePromiseClient, TS output generates single*ServiceClientclass with method overloads.Proposition.
The above issues might get just fixed, which from first look at the source code doesn't look too complicated. Only the part with overloading might cause some problems in typescript generated function body, because of extra logic needed to figure out if the argument is
callbackfunction, oroptionsobject. However, there might be a way to overcome this complications, if there is a chance to change the generated API.Could the generated API follow a little different approach, exposing separate methods for different
callmethods? Instead of separate client classes and/or method overloading, have a single class withmethodNameUnaryandmethodNamePromiseandmethodNameRpc? One callingunaryCallother callingthenableCall, etc.I believe this way would be more explicit and also might be a bit easier to maintain in the generator. I also think, this proposed change could be done in a non-breaking way, leaving current API as it is and just adding new explicit ones next to that.
👋