From f83f573e2e4a87ed2718c93e9d20b57413628dc0 Mon Sep 17 00:00:00 2001 From: Yash Singh Date: Mon, 18 Aug 2025 16:24:42 -0500 Subject: [PATCH 1/2] fix: make all partial args result in optional arg --- .../convex-helpers/react/sessions.test.ts | 22 +++++++++++++++++++ packages/convex-helpers/react/sessions.ts | 16 +++++++++++--- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/packages/convex-helpers/react/sessions.test.ts b/packages/convex-helpers/react/sessions.test.ts index 0e421a3c..213f3077 100644 --- a/packages/convex-helpers/react/sessions.test.ts +++ b/packages/convex-helpers/react/sessions.test.ts @@ -26,6 +26,17 @@ expectTypeOf< > >().toEqualTypeOf<[{ arg: string } | "skip"]>(); +expectTypeOf< + SessionQueryArgsArray< + FunctionReference< + "query", + "public", + { arg?: string; sessionId: SessionId | null }, + any + > + > +>().toEqualTypeOf<[args?: { arg?: string } | "skip"]>(); + expectTypeOf< SessionQueryArgsArray< FunctionReference<"query", "public", { sessionId: SessionId | null }, any> @@ -43,6 +54,17 @@ expectTypeOf< > >().toEqualTypeOf<[{ arg: string }]>(); +expectTypeOf< + SessionArgsArray< + FunctionReference< + "mutation", + "public", + { arg?: string; sessionId: SessionId }, + any + > + > +>().toEqualTypeOf<[args?: { arg?: string }]>(); + expectTypeOf< SessionArgsArray< FunctionReference<"mutation", "public", { sessionId: SessionId }, any> diff --git a/packages/convex-helpers/react/sessions.ts b/packages/convex-helpers/react/sessions.ts index aad57ff7..8d37f401 100644 --- a/packages/convex-helpers/react/sessions.ts +++ b/packages/convex-helpers/react/sessions.ts @@ -73,23 +73,33 @@ type SessionFunction< Args = any, > = FunctionReference; +type ArgsWithoutSession< + Fn extends SessionFunction<"query" | "mutation" | "action">, +> = BetterOmit, "sessionId">; + export type SessionQueryArgsArray> = keyof FunctionArgs extends "sessionId" ? [args?: EmptyObject | "skip"] - : [args: BetterOmit, "sessionId"> | "skip"]; + : Partial> extends ArgsWithoutSession + ? [args?: ArgsWithoutSession | "skip"] + : [args: ArgsWithoutSession | "skip"]; export type SessionArgsArray< Fn extends SessionFunction<"query" | "mutation" | "action">, > = keyof FunctionArgs extends "sessionId" ? [args?: EmptyObject] - : [args: BetterOmit, "sessionId">]; + : Partial> extends ArgsWithoutSession + ? [args?: ArgsWithoutSession] + : [args: ArgsWithoutSession]; export type SessionArgsAndOptions< Fn extends SessionFunction<"mutation">, Options, > = keyof FunctionArgs extends "sessionId" ? [args?: EmptyObject, options?: Options] - : [args: BetterOmit, "sessionId">, options?: Options]; + : Partial> extends ArgsWithoutSession + ? [args: ArgsWithoutSession, options?: Options] + : [args: ArgsWithoutSession, options?: Options]; type SessionPaginatedQueryFunction< Args extends { paginationOpts: PaginationOptions } = { From 4e186e00367061d06702b963597e493787200c15 Mon Sep 17 00:00:00 2001 From: Yash Singh Date: Mon, 18 Aug 2025 17:05:14 -0500 Subject: [PATCH 2/2] whoops forgot on SessionArgsAndOptions --- packages/convex-helpers/react/sessions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/convex-helpers/react/sessions.ts b/packages/convex-helpers/react/sessions.ts index 8d37f401..60b5edea 100644 --- a/packages/convex-helpers/react/sessions.ts +++ b/packages/convex-helpers/react/sessions.ts @@ -98,7 +98,7 @@ export type SessionArgsAndOptions< > = keyof FunctionArgs extends "sessionId" ? [args?: EmptyObject, options?: Options] : Partial> extends ArgsWithoutSession - ? [args: ArgsWithoutSession, options?: Options] + ? [args?: ArgsWithoutSession, options?: Options] : [args: ArgsWithoutSession, options?: Options]; type SessionPaginatedQueryFunction<