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

Declare generated GrpcType inheritance #2852

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

enderteszla
Copy link

Generated interface ProtoGrpcType is in fact an extension of grpc.GrpcObject, but this inheritance wasn't declared until now.

This forced users to cast grpc.loadPackageDefinition(...): grpc.GrpcObject first to as unknown and only then to as {GeneratedGrpcType}.

With this fix users will be able to cast to as {GeneratedGrpcType} directly.

Fixes #2851

Generated interface ProtoGrpcType is in fact an extension of grpc.GrpcObject, but this inheritance wasn't declared until now.

This forced users to cast `grpc.loadPackageDefinition(...): grpc.GrpcObject` first to `as unknown` and only then to `as {GeneratedGrpcType}`.

With this fix users will be able to cast to `as {GeneratedGrpcType}` directly.
Copy link

linux-foundation-easycla bot commented Nov 17, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

Copy link
Member

@murgatroid99 murgatroid99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please run npm run generate-golden in packages/proto-loader and update the example in the README.

@@ -82,7 +82,7 @@ describe('Channelz', () => {
channelzClient = new channelzGrpcObject.grpc.channelz.v1.Channelz(
`localhost:${port}`,
grpc.credentials.createInsecure()
);
) as ChannelzClient;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the purpose of this change is to avoid typecasts, why do we need to add one here? If you change the typecast on line 37 to the new suggested usage, would this one still be required?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@murgatroid99 , fixed. Thank you!

@enderteszla enderteszla force-pushed the enderteszla-patch-1 branch 3 times, most recently from f64867e to ab0c2ff Compare November 19, 2024 17:08
Copy link
Member

@murgatroid99 murgatroid99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert the changes to the grpc-health-check package except for the ones that are direct consequences of the code generator change. In particular the published code should not interact with @grpc/grpc-js at all. This is a deliberate design decision to make the library compatible with both gRPC implementations. Modifications to that design can be discussed separately but they are out of scope for this change.

On a separate note, this change fully breaks compatibility with the old grpc package. That package does not export ServiceClient or ServiceClientConstructor types, and its grpc.GrpcObject is not compatible with the one this generator generates. That library still has 180K+ weekly downloads, so it's possible that this change will break people, and if we need to revert it that will be disruptive to a lot of people. If there is a way to avoid that breakage I would have a lot more confidence in publishing this change.

const proto = (grpc.loadPackageDefinition(
packageDefinition
) as unknown) as ProtoGrpcType;
const proto: ProtoGrpcType = grpc.loadPackageDefinition(packageDefinition);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the modified usage in other files, as ProtoGrpcType appears to still be required, so that should also be specified here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

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 this pull request may close these issues.

Not declaring generated ProtoGrpcType inheritance
2 participants