You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The typescript generator introduced in #1474 produces an incorrect/incomplete type for services in loaded protos. Referencing the golden-generated output, the type of the service field is ServiceDefinition.
constpackageDefinition=(protoLoader.loadSync(...)asunknown)asProtoGrpcType;constserver=newgrpc.Server();server.addService(packageDefinition.google.showcase.v1beta1.Echo.service,// ~~~~~~ TS: Argument of type 'ServiceDefinition' is not assignable to parameter of type 'ServiceDefinition<{ Block: ..., Chat: ..., ...}>'{Block: ...,Chat: ..., ... })
I think the type can be improved without changing the generated code much by injecting a custom ServiceDefinition type based on the one in the native grpc package, or maybe the related one in @grpc/proto-loader could just be replaced instead.
typeServiceDefinition<ImplementationTypeextendsgrpc.UntypedServiceImplementation=grpc.UntypedServiceImplementation>={[KinkeyofImplementationType]: MethodDefinition<Parameters<ImplementationType[K]>[0],// Request TypeReturnType<ImplementationType[K]>// Return Type>;};// ... later in e.g. echo.ts
Echo: SubtypeConstructor<typeofgrpc.Client,_google_showcase_v1beta1_EchoClient>&{service: ServiceDefinition<EchoHandlers>}
One solution here may be to loosen the type parameter in the native grpc package to avoid this kind of problem. That current type may not even be correct in all cases.
Another good alternative may be to explicitly generate the service definition type along with each service implementation type. In your suggestion you are using generics to extract the service definition type from the implementation type, but we can take advantage of the fact that the details of the implementation type are known at generation time.
So, it would be something like this in google/showcase/v1beta1/Echo.ts:
Problem description
The typescript generator introduced in #1474 produces an incorrect/incomplete type for services in loaded protos. Referencing the golden-generated output, the type of the
service
field isServiceDefinition
.This causes problems with the type of
server.addService
in the native grpc package:I think the type can be improved without changing the generated code much by injecting a custom
ServiceDefinition
type based on the one in the native grpc package, or maybe the related one in@grpc/proto-loader
could just be replaced instead.Environment
@grpc/[email protected]
The text was updated successfully, but these errors were encountered: