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

V2: Update makeAnyClient signature to carry type information to narrow down method kinds #1292

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Update makeAnyClient signature to carry type information to narrow do…
…wn method kinds

Signed-off-by: Timo Stamm <ts@timostamm.de>
timostamm committed Oct 31, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit bc623b6943272e3784ee5d573e130f5f6d52cbf1
4 changes: 2 additions & 2 deletions packages/connect/src/any-client.ts
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import type { DescMethod, DescService } from "@bufbuild/protobuf";
import type { DescService, DescMethodUnary, DescMethodStreaming } from "@bufbuild/protobuf";

/**
* AnyClient is an arbitrary service client with any method signature.
@@ -24,7 +24,7 @@ export type AnyClient = Record<string, AnyClientMethod>;

type AnyClientMethod = (...args: any[]) => any; // eslint-disable-line @typescript-eslint/no-explicit-any

type CreateAnyClientMethod = (method: DescMethod) => AnyClientMethod | null;
type CreateAnyClientMethod = (method: DescMethodUnary | DescMethodStreaming) => AnyClientMethod | null;

/**
* Create any client for the given service.
3 changes: 1 addition & 2 deletions packages/connect/src/promise-client.ts
Original file line number Diff line number Diff line change
@@ -20,7 +20,6 @@ import type {
DescMethodBiDiStreaming,
DescMethodClientStreaming,
DescMethodServerStreaming,
DescMethodStreaming,
DescMethodUnary,
} from "@bufbuild/protobuf";
import type { Transport } from "./transport.js";
@@ -56,7 +55,7 @@ export function createClient<T extends DescService>(
) {
return makeAnyClient(
service,
(method: DescMethodUnary | DescMethodStreaming) => {
(method) => {
switch (method.methodKind) {
case "unary":
return createUnaryFn(transport, method);