Skip to content

Commit e4561bd

Browse files
committed
try skip overload
1 parent 85f1f0e commit e4561bd

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
@@ -649,20 +649,26 @@ export type OptionalRestArgsOrSkip<FuncRef extends FunctionReference<any>> =
649649
*
650650
* @public
651651
*/
652-
export type UseQueryOptions<Query extends FunctionReference<"query">> =
653-
QueryOptions<Query> & {
654-
/**
655-
* Whether to throw an error if the query fails.
656-
* If false, the error will be returned in the `error` field.
657-
* @defaultValue false
658-
*/
659-
throwOnError?: boolean;
660-
/**
661-
* An initial value to use before the query result is available.
662-
* @defaultValue undefined
663-
*/
664-
initialValue?: Query["_returnType"];
665-
};
652+
export type UseQueryOptions<Query extends FunctionReference<"query">> = (
653+
| (QueryOptions<Query> & { skip?: false })
654+
| {
655+
query: Query;
656+
args?: NoInfer<unknown>;
657+
skip: true;
658+
}
659+
) & {
660+
/**
661+
* Whether to throw an error if the query fails.
662+
* If false, the error will be returned in the `error` field.
663+
* @defaultValue false
664+
*/
665+
throwOnError?: boolean;
666+
/**
667+
* An initial value to use before the query result is available.
668+
* @defaultValue undefined
669+
*/
670+
initialValue?: Query["_returnType"];
671+
};
666672

667673
/**
668674
* Options for the object-based {@link useQuery} overload with a preloaded query.
@@ -782,7 +788,9 @@ export function useQuery<Query extends FunctionReference<"query">>(
782788
typeof query === "string"
783789
? (makeFunctionReference<"query", any, any>(query) as Query)
784790
: query;
785-
argsObject = queryOrOptions.args ?? ({} as Record<string, Value>);
791+
if (!queryOrOptions.skip && queryOrOptions.args) {
792+
argsObject = queryOrOptions.args;
793+
}
786794
throwOnError = queryOrOptions.throwOnError ?? false;
787795
initialValue = queryOrOptions.initialValue;
788796
}

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)