Skip to content

Commit 39ebd9c

Browse files
committed
try skip overload
1 parent ccad381 commit 39ebd9c

File tree

3 files changed

+30
-16
lines changed

3 files changed

+30
-16
lines changed

npm-packages/convex/src/browser/query_options.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ export type QueryOptions<Query extends FunctionReference<"query">> = {
2222
// This helper helps more once we have more inference happening.
2323
export function convexQueryOptions<Query extends FunctionReference<"query">>(
2424
options: QueryOptions<Query>,
25-
) {
25+
): QueryOptions<Query> {
2626
return options;
2727
}

npm-packages/convex/src/react/client.ts

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -808,20 +808,26 @@ export type OptionalRestArgsOrSkip<FuncRef extends FunctionReference<any>> =
808808
*
809809
* @public
810810
*/
811-
export type UseQueryOptions<Query extends FunctionReference<"query">> =
812-
QueryOptions<Query> & {
813-
/**
814-
* Whether to throw an error if the query fails.
815-
* If false, the error will be returned in the `error` field.
816-
* @defaultValue false
817-
*/
818-
throwOnError?: boolean;
819-
/**
820-
* An initial value to use before the query result is available.
821-
* @defaultValue undefined
822-
*/
823-
initialValue?: Query["_returnType"];
824-
};
811+
export type UseQueryOptions<Query extends FunctionReference<"query">> = (
812+
| (QueryOptions<Query> & { skip?: false })
813+
| {
814+
query: Query;
815+
args?: NoInfer<unknown>;
816+
skip: true;
817+
}
818+
) & {
819+
/**
820+
* Whether to throw an error if the query fails.
821+
* If false, the error will be returned in the `error` field.
822+
* @defaultValue false
823+
*/
824+
throwOnError?: boolean;
825+
/**
826+
* An initial value to use before the query result is available.
827+
* @defaultValue undefined
828+
*/
829+
initialValue?: Query["_returnType"];
830+
};
825831

826832
/**
827833
* Options for the object-based {@link useQuery} overload with a preloaded query.
@@ -941,7 +947,9 @@ export function useQuery<Query extends FunctionReference<"query">>(
941947
typeof query === "string"
942948
? (makeFunctionReference<"query", any, any>(query) as Query)
943949
: query;
944-
argsObject = queryOrOptions.args ?? ({} as Record<string, Value>);
950+
if (!queryOrOptions.skip && queryOrOptions.args) {
951+
argsObject = queryOrOptions.args;
952+
}
945953
throwOnError = queryOrOptions.throwOnError ?? false;
946954
initialValue = queryOrOptions.initialValue;
947955
}

npm-packages/convex/src/react/use_query.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ describe("useQuery types", () => {
8686
args: { _arg: "asdf" },
8787
});
8888

89+
useQuery({
90+
query: api.module.args,
91+
args: { anyarg: 0 },
92+
skip: true,
93+
});
94+
8995
useQuery({
9096
query: api.module.args,
9197
args: { _arg: "asdf" },

0 commit comments

Comments
 (0)