-
Notifications
You must be signed in to change notification settings - Fork 80
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
No export for UnaryImpl
provided
#788
Comments
Hey Sasha, we do not export all types to keep the API surface manageable. It would be very difficult to make any non-breaking changes otherwise. Can you get by with |
For example, here is how you could extract a specific signature: import type {MethodInfo, PartialMessage,} from "@bufbuild/protobuf";
import {Int32Value, MethodKind, StringValue} from "@bufbuild/protobuf";
import type {HandlerContext, MethodImpl} from "@connectrpc/connect";
type U = MethodImpl<MethodInfo<Int32Value, StringValue> & { kind: MethodKind.Unary }>;
export const u: U = (request: Int32Value, context: HandlerContext): PartialMessage<StringValue> => {
context.signal.throwIfAborted();
return {value: request.value.toString()};
} How do you want to use the type? Feedback is much appreciated, so that we can consider it going forward. |
This is how I'm currently using it: getUsers: UnaryImpl<GetUsersRequest, GetUsersResponse> = async (req, ctx) => {
return new GetUsersResponse();
}; as opposed to: async getUsers(
req: GetUserRequest,
ctx: HandlerContext,
) {
return new GetUsersResponse();
} Doesn't really matter either way, it's also the way that most editors with intellisense will scaffold the property for you |
Ah, so the IDE is scaffolding an implementation with Can you provide some details? I can't reproduce with VS code or JetBrains, but I might not be hitting the right buttons. |
Thanks for the context, @sachaw. The recommended implementation using classes would be: class Model implements ServiceImpl<typeof ModelService> {
addServer(request: AddServerRequest) {
// do something with the request...
return new AddServerResponse();
}
} Note that the typing for the |
I think we should be able to get a IDE suggestion matching our recommendation by "unrolling" the types for service methods: connect-es/packages/connect/src/implementation.ts Lines 44 to 45 in 83dbda3
Similar to how we do it for client methods: connect-es/packages/connect/src/promise-client.ts Lines 39 to 41 in 83dbda3
|
When using modern Node module resolution, there is no export provided that gives access to the
UnaryImpl
type from https://github.com/connectrpc/connect-es/blob/main/packages/connect/src/implementation.tsIt is likely easiest to just re-export it, instead of having a dedicated entry point,
The text was updated successfully, but these errors were encountered: