Skip to content

Commit

Permalink
fix: type TQueryKey in getOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
liaoxuan committed Oct 20, 2023
1 parent 428ad94 commit 730b570
Showing 1 changed file with 9 additions and 23 deletions.
32 changes: 9 additions & 23 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type CompatibleWithV4<V5, V4> =
type CompatibleQueryFunction<
T = unknown,
TQueryKey extends QueryKey = QueryKey,
TPageParam = unknown
TPageParam = never
> = CompatibleWithV4<
QueryFunction<T, TQueryKey, TPageParam>,
QueryFunction<T, TQueryKey>
Expand Down Expand Up @@ -106,9 +106,7 @@ export type inferQueryKey<
> = CompatibleWithV4<
DataTag<
GetQueryKey<TVariables>,
[TPageParam] extends [never]
? TFnData
: CompatibleInfiniteData<TFnData, TPageParam>
[TPageParam] extends [never] ? TFnData : InfiniteData<TFnData, TPageParam>
>,
GetQueryKey<TVariables>
>
Expand Down Expand Up @@ -155,14 +153,13 @@ export type ExposeMethods<TFnData, TVariables, TError, TPageParam = never> = {
variables: TVariables extends void ? TVariables | void : TVariables
) => [TPageParam] extends [never]
? {
queryKey: inferQueryKey<TFnData, TVariables, TPageParam>
queryKey: inferQueryKey<TFnData, TVariables>
queryFn: CompatibleQueryFunction<
TFnData,
inferQueryKey<TFnData, TVariables, TPageParam>,
TPageParam
inferQueryKey<TFnData, TVariables>
>
queryKeyHashFn?: QueryKeyHashFunction<
inferQueryKey<TFnData, TVariables, TPageParam>
inferQueryKey<TFnData, TVariables>
>
}
: {
Expand All @@ -184,24 +181,13 @@ export type ExposeMethods<TFnData, TVariables, TError, TPageParam = never> = {
TFnData,
TError,
TFnData,
inferQueryKey<
TVariables,
[TPageParam] extends [never]
? TFnData
: CompatibleInfiniteData<TFnData, TPageParam>
>
DataTag<GetQueryKey<TVariables>, TFnData>
>,
// Not work to infer TError in v4
{
queryKey: inferQueryKey<TFnData, TVariables, TPageParam>
queryFn: CompatibleQueryFunction<
TFnData,
inferQueryKey<TFnData, TVariables, TPageParam>,
TPageParam
>
queryKeyHashFn?: QueryKeyHashFunction<
inferQueryKey<TFnData, TVariables, TPageParam>
>
queryKey: GetQueryKey<TVariables>
queryFn: QueryFunction<TFnData, GetQueryKey<TVariables>>
queryKeyHashFn?: QueryKeyHashFunction<GetQueryKey<TVariables>>
}
>
: CompatibleUseInfiniteQueryOptions<
Expand Down

0 comments on commit 730b570

Please sign in to comment.