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

Not declaring generated ProtoGrpcType inheritance #2851

Open
enderteszla opened this issue Nov 17, 2024 · 1 comment · May be fixed by #2852
Open

Not declaring generated ProtoGrpcType inheritance #2851

enderteszla opened this issue Nov 17, 2024 · 1 comment · May be fixed by #2852

Comments

@enderteszla
Copy link

Problem description

When using proto-loader-gen-types for ts-types generating, the root ProtoGrpcType type is not declared to extends grpc.GrpcObject.
Because of that, when I grpc.loadPackageDefinition(...), I cannot cast it directly to as MyProtoGrpcType and I have to cast it to as unknown first.
Though root ProtoGrpcType is in fact the extension of grpc.GrpcObject -- the only problem is the absence of declaration.

Reproduction steps

import * as grpc from '@grpc/grpc-js';
import * as protoLoader from '@grpc/proto-loader';
import type { ProtoGrpcType as MyProtoGrpcType } from 'proto/my';

const myPackageDefinition = protoLoader.loadSync('my.proto', { includeDirs: [ 'proto' ] });
const myProtoDescriptor = grpc.loadPackageDefinition(myPackageDefinition) as unknown as MyGrpcType;

Environment

  • Any OS name, version and architecture
  • Any Node version
  • Any Node installation method (nvm or others)
  • @grpc/proto-loader:0.7.13

Additional context

@murgatroid99 , I strongly appreciate your creature: the proto-loader-gen-types!
It is a very helpful thing! And I even can go on with as unknown cast.
But this duct-tape of as unknown can be removed -- and please let's do it.
I created a PR addressing this problem, it's very simple. Please take a look.

@enderteszla enderteszla linked a pull request Nov 17, 2024 that will close this issue
@enderteszla
Copy link
Author

I should add: the same thing happens with ServiceClient we're building from ServiceClientConstructor in that very GrpcObject. The generated client always de facto implements grpc.ServiceClient -- though it's not declared. So for now user has to cast as unknown first and only then cast as {MyServiceClient}.

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

Successfully merging a pull request may close this issue.

1 participant