Skip to content

Commit

Permalink
types(react-query): rename useSuspenseQueries, useQueries internal ty…
Browse files Browse the repository at this point in the history
…pe name intuitively (#7216)
  • Loading branch information
manudeli authored Apr 9, 2024
1 parent 565a241 commit 3fa5323
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
24 changes: 12 additions & 12 deletions packages/react-query/src/useQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type UseQueryOptionsForUseQueries<
// Avoid TS depth-limit error in case of large array literal
type MAXIMUM_DEPTH = 20

type GetOptions<T> =
type GetUseQueryOptionsForUseQueries<T> =
// Part 1: responsible for applying explicit type parameter to function arguments, if object { queryFnData: TQueryFnData, error: TError, data: TData }
T extends {
queryFnData: infer TQueryFnData
Expand Down Expand Up @@ -120,7 +120,7 @@ type GetDefinedOrUndefinedQueryResult<T, TData, TError = unknown> = T extends {
: UseQueryResult<TData, TError>
: UseQueryResult<TData, TError>

type GetResults<T> =
type GetUseQueryResult<T> =
// Part 1: responsible for mapping explicit type parameter to function result, if object
T extends { queryFnData: any; error?: infer TError; data: infer TData }
? GetDefinedOrUndefinedQueryResult<T, TData, TError>
Expand Down Expand Up @@ -165,18 +165,18 @@ type GetResults<T> =
*/
export type QueriesOptions<
T extends Array<any>,
TResult extends Array<any> = [],
TResults extends Array<any> = [],
TDepth extends ReadonlyArray<number> = [],
> = TDepth['length'] extends MAXIMUM_DEPTH
? Array<UseQueryOptionsForUseQueries>
: T extends []
? []
: T extends [infer Head]
? [...TResult, GetOptions<Head>]
: T extends [infer Head, ...infer Tail]
? [...TResults, GetUseQueryOptionsForUseQueries<Head>]
: T extends [infer Head, ...infer Tails]
? QueriesOptions<
[...Tail],
[...TResult, GetOptions<Head>],
[...Tails],
[...TResults, GetUseQueryOptionsForUseQueries<Head>],
[...TDepth, 1]
>
: ReadonlyArray<unknown> extends T
Expand Down Expand Up @@ -207,18 +207,18 @@ export type QueriesOptions<
*/
export type QueriesResults<
T extends Array<any>,
TResult extends Array<any> = [],
TResults extends Array<any> = [],
TDepth extends ReadonlyArray<number> = [],
> = TDepth['length'] extends MAXIMUM_DEPTH
? Array<UseQueryResult>
: T extends []
? []
: T extends [infer Head]
? [...TResult, GetResults<Head>]
: T extends [infer Head, ...infer Tail]
? [...TResults, GetUseQueryResult<Head>]
: T extends [infer Head, ...infer Tails]
? QueriesResults<
[...Tail],
[...TResult, GetResults<Head>],
[...Tails],
[...TResults, GetUseQueryResult<Head>],
[...TDepth, 1]
>
: T extends Array<
Expand Down
24 changes: 12 additions & 12 deletions packages/react-query/src/useSuspenseQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type {
// Avoid TS depth-limit error in case of large array literal
type MAXIMUM_DEPTH = 20

type GetSuspenseOptions<T> =
type GetUseSuspenseQueryOptions<T> =
// Part 1: responsible for applying explicit type parameter to function arguments, if object { queryFnData: TQueryFnData, error: TError, data: TData }
T extends {
queryFnData: infer TQueryFnData
Expand Down Expand Up @@ -61,7 +61,7 @@ type GetSuspenseOptions<T> =
: // Fallback
UseSuspenseQueryOptions

type GetSuspenseResults<T> =
type GetUseSuspenseQueryResult<T> =
// Part 1: responsible for mapping explicit type parameter to function result, if object
T extends { queryFnData: any; error?: infer TError; data: infer TData }
? UseSuspenseQueryResult<TData, TError>
Expand Down Expand Up @@ -104,18 +104,18 @@ type GetSuspenseResults<T> =
*/
export type SuspenseQueriesOptions<
T extends Array<any>,
TResult extends Array<any> = [],
TResults extends Array<any> = [],
TDepth extends ReadonlyArray<number> = [],
> = TDepth['length'] extends MAXIMUM_DEPTH
? Array<UseSuspenseQueryOptions>
: T extends []
? []
: T extends [infer Head]
? [...TResult, GetSuspenseOptions<Head>]
: T extends [infer Head, ...infer Tail]
? [...TResults, GetUseSuspenseQueryOptions<Head>]
: T extends [infer Head, ...infer Tails]
? SuspenseQueriesOptions<
[...Tail],
[...TResult, GetSuspenseOptions<Head>],
[...Tails],
[...TResults, GetUseSuspenseQueryOptions<Head>],
[...TDepth, 1]
>
: Array<unknown> extends T
Expand All @@ -141,18 +141,18 @@ export type SuspenseQueriesOptions<
*/
export type SuspenseQueriesResults<
T extends Array<any>,
TResult extends Array<any> = [],
TResults extends Array<any> = [],
TDepth extends ReadonlyArray<number> = [],
> = TDepth['length'] extends MAXIMUM_DEPTH
? Array<UseSuspenseQueryResult>
: T extends []
? []
: T extends [infer Head]
? [...TResult, GetSuspenseResults<Head>]
: T extends [infer Head, ...infer Tail]
? [...TResults, GetUseSuspenseQueryResult<Head>]
: T extends [infer Head, ...infer Tails]
? SuspenseQueriesResults<
[...Tail],
[...TResult, GetSuspenseResults<Head>],
[...Tails],
[...TResults, GetUseSuspenseQueryResult<Head>],
[...TDepth, 1]
>
: T extends Array<
Expand Down

0 comments on commit 3fa5323

Please sign in to comment.