@tanstack/react-query 5.28.14 → 5.29.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/codemods/coverage/clover.xml +2 -2
- package/build/codemods/coverage/index.html +1 -1
- package/build/codemods/coverage/utils/index.html +1 -1
- package/build/codemods/coverage/utils/index.js.html +1 -1
- package/build/codemods/coverage/utils/transformers/index.html +1 -1
- package/build/codemods/coverage/utils/transformers/query-cache-transformer.js.html +1 -1
- package/build/codemods/coverage/utils/transformers/query-client-transformer.js.html +1 -1
- package/build/codemods/coverage/utils/transformers/use-query-like-transformer.js.html +1 -1
- package/build/codemods/coverage/v4/index.html +1 -1
- package/build/codemods/coverage/v4/key-transformation.js.html +1 -1
- package/build/codemods/coverage/v4/replace-import-specifier.js.html +1 -1
- package/build/codemods/coverage/v4/utils/replacers/index.html +1 -1
- package/build/codemods/coverage/v4/utils/replacers/key-replacer.js.html +1 -1
- package/build/codemods/coverage/v5/is-loading/index.html +1 -1
- package/build/codemods/coverage/v5/is-loading/is-loading.js.html +1 -1
- package/build/codemods/coverage/v5/keep-previous-data/index.html +1 -1
- package/build/codemods/coverage/v5/keep-previous-data/keep-previous-data.js.html +1 -1
- package/build/codemods/coverage/v5/keep-previous-data/utils/already-has-placeholder-data-property.js.html +1 -1
- package/build/codemods/coverage/v5/keep-previous-data/utils/index.html +1 -1
- package/build/codemods/coverage/v5/remove-overloads/index.html +1 -1
- package/build/codemods/coverage/v5/remove-overloads/remove-overloads.js.html +1 -1
- package/build/codemods/coverage/v5/remove-overloads/transformers/filter-aware-usage-transformer.js.html +1 -1
- package/build/codemods/coverage/v5/remove-overloads/transformers/index.html +1 -1
- package/build/codemods/coverage/v5/remove-overloads/transformers/query-fn-aware-usage-transformer.js.html +1 -1
- package/build/codemods/coverage/v5/remove-overloads/utils/index.html +1 -1
- package/build/codemods/coverage/v5/remove-overloads/utils/index.js.html +1 -1
- package/build/codemods/coverage/v5/remove-overloads/utils/unknown-usage-error.js.html +1 -1
- package/build/codemods/coverage/v5/rename-hydrate/index.html +1 -1
- package/build/codemods/coverage/v5/rename-hydrate/rename-hydrate.js.html +1 -1
- package/build/codemods/coverage/v5/rename-properties/index.html +1 -1
- package/build/codemods/coverage/v5/rename-properties/rename-properties.js.html +1 -1
- package/build/legacy/infiniteQueryOptions.cjs.map +1 -1
- package/build/legacy/infiniteQueryOptions.d.cts +2 -2
- package/build/legacy/infiniteQueryOptions.d.ts +2 -2
- package/build/legacy/infiniteQueryOptions.js.map +1 -1
- package/build/legacy/queryOptions.cjs.map +1 -1
- package/build/legacy/queryOptions.d.cts +2 -2
- package/build/legacy/queryOptions.d.ts +2 -2
- package/build/legacy/queryOptions.js.map +1 -1
- package/build/legacy/useInfiniteQuery.cjs.map +1 -1
- package/build/legacy/useInfiniteQuery.d.cts +3 -3
- package/build/legacy/useInfiniteQuery.d.ts +3 -3
- package/build/legacy/useInfiniteQuery.js.map +1 -1
- package/build/legacy/useQueries.cjs.map +1 -1
- package/build/legacy/useQueries.d.cts +10 -10
- package/build/legacy/useQueries.d.ts +10 -10
- package/build/legacy/useQueries.js.map +1 -1
- package/build/legacy/useQuery.cjs.map +1 -1
- package/build/legacy/useQuery.d.cts +3 -3
- package/build/legacy/useQuery.d.ts +3 -3
- package/build/legacy/useQuery.js.map +1 -1
- package/build/legacy/useSuspenseQueries.cjs.map +1 -1
- package/build/legacy/useSuspenseQueries.d.cts +10 -10
- package/build/legacy/useSuspenseQueries.d.ts +10 -10
- package/build/legacy/useSuspenseQueries.js.map +1 -1
- package/build/modern/infiniteQueryOptions.cjs.map +1 -1
- package/build/modern/infiniteQueryOptions.d.cts +2 -2
- package/build/modern/infiniteQueryOptions.d.ts +2 -2
- package/build/modern/infiniteQueryOptions.js.map +1 -1
- package/build/modern/queryOptions.cjs.map +1 -1
- package/build/modern/queryOptions.d.cts +2 -2
- package/build/modern/queryOptions.d.ts +2 -2
- package/build/modern/queryOptions.js.map +1 -1
- package/build/modern/useInfiniteQuery.cjs.map +1 -1
- package/build/modern/useInfiniteQuery.d.cts +3 -3
- package/build/modern/useInfiniteQuery.d.ts +3 -3
- package/build/modern/useInfiniteQuery.js.map +1 -1
- package/build/modern/useQueries.cjs.map +1 -1
- package/build/modern/useQueries.d.cts +10 -10
- package/build/modern/useQueries.d.ts +10 -10
- package/build/modern/useQueries.js.map +1 -1
- package/build/modern/useQuery.cjs.map +1 -1
- package/build/modern/useQuery.d.cts +3 -3
- package/build/modern/useQuery.d.ts +3 -3
- package/build/modern/useQuery.js.map +1 -1
- package/build/modern/useSuspenseQueries.cjs.map +1 -1
- package/build/modern/useSuspenseQueries.d.cts +10 -10
- package/build/modern/useSuspenseQueries.d.ts +10 -10
- package/build/modern/useSuspenseQueries.js.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/useQueries.test.tsx +153 -1
- package/src/infiniteQueryOptions.ts +4 -4
- package/src/queryOptions.ts +4 -4
- package/src/useInfiniteQuery.ts +4 -4
- package/src/useQueries.ts +12 -12
- package/src/useQuery.ts +4 -4
- package/src/useSuspenseQueries.ts +12 -12
|
@@ -2,11 +2,13 @@ import { describe, expect, expectTypeOf, it, vi } from 'vitest'
|
|
|
2
2
|
import { fireEvent, render, waitFor } from '@testing-library/react'
|
|
3
3
|
import * as React from 'react'
|
|
4
4
|
import { ErrorBoundary } from 'react-error-boundary'
|
|
5
|
+
import { QueryClient } from '@tanstack/query-core'
|
|
5
6
|
import { QueryCache, queryOptions, skipToken, useQueries } from '..'
|
|
6
7
|
import { createQueryClient, queryKey, renderWithClient, sleep } from './utils'
|
|
7
8
|
import type {
|
|
8
9
|
QueryFunction,
|
|
9
10
|
QueryKey,
|
|
11
|
+
QueryObserverResult,
|
|
10
12
|
UseQueryOptions,
|
|
11
13
|
UseQueryResult,
|
|
12
14
|
} from '..'
|
|
@@ -975,7 +977,7 @@ describe('useQueries', () => {
|
|
|
975
977
|
)
|
|
976
978
|
})
|
|
977
979
|
|
|
978
|
-
it
|
|
980
|
+
it('should not return new instances when called without queries', async () => {
|
|
979
981
|
const key = queryKey()
|
|
980
982
|
const ids: Array<number> = []
|
|
981
983
|
let resultChanged = 0
|
|
@@ -1278,4 +1280,154 @@ describe('useQueries', () => {
|
|
|
1278
1280
|
|
|
1279
1281
|
await waitFor(() => rendered.getByText('data: 1 result'))
|
|
1280
1282
|
})
|
|
1283
|
+
|
|
1284
|
+
it('should optimize combine if it is a stable reference', async () => {
|
|
1285
|
+
const key1 = queryKey()
|
|
1286
|
+
const key2 = queryKey()
|
|
1287
|
+
|
|
1288
|
+
const client = new QueryClient()
|
|
1289
|
+
|
|
1290
|
+
const spy = vi.fn()
|
|
1291
|
+
let value = 0
|
|
1292
|
+
|
|
1293
|
+
function Page() {
|
|
1294
|
+
const [state, setState] = React.useState(0)
|
|
1295
|
+
const queries = useQueries(
|
|
1296
|
+
{
|
|
1297
|
+
queries: [
|
|
1298
|
+
{
|
|
1299
|
+
queryKey: key1,
|
|
1300
|
+
queryFn: async () => {
|
|
1301
|
+
await sleep(10)
|
|
1302
|
+
return 'first result:' + value
|
|
1303
|
+
},
|
|
1304
|
+
},
|
|
1305
|
+
{
|
|
1306
|
+
queryKey: key2,
|
|
1307
|
+
queryFn: async () => {
|
|
1308
|
+
await sleep(20)
|
|
1309
|
+
return 'second result:' + value
|
|
1310
|
+
},
|
|
1311
|
+
},
|
|
1312
|
+
],
|
|
1313
|
+
combine: React.useCallback((results: Array<QueryObserverResult>) => {
|
|
1314
|
+
const result = {
|
|
1315
|
+
combined: true,
|
|
1316
|
+
res: results.map((res) => res.data).join(','),
|
|
1317
|
+
}
|
|
1318
|
+
spy(result)
|
|
1319
|
+
return result
|
|
1320
|
+
}, []),
|
|
1321
|
+
},
|
|
1322
|
+
client,
|
|
1323
|
+
)
|
|
1324
|
+
|
|
1325
|
+
return (
|
|
1326
|
+
<div>
|
|
1327
|
+
<div>
|
|
1328
|
+
data: {String(queries.combined)} {queries.res}
|
|
1329
|
+
</div>
|
|
1330
|
+
<button onClick={() => setState(state + 1)}>rerender</button>
|
|
1331
|
+
</div>
|
|
1332
|
+
)
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1335
|
+
const rendered = render(<Page />)
|
|
1336
|
+
|
|
1337
|
+
await waitFor(() =>
|
|
1338
|
+
rendered.getByText('data: true first result:0,second result:0'),
|
|
1339
|
+
)
|
|
1340
|
+
|
|
1341
|
+
// both pending, one pending, both resolved
|
|
1342
|
+
expect(spy).toHaveBeenCalledTimes(3)
|
|
1343
|
+
|
|
1344
|
+
await client.refetchQueries()
|
|
1345
|
+
// no increase because result hasn't changed
|
|
1346
|
+
expect(spy).toHaveBeenCalledTimes(3)
|
|
1347
|
+
|
|
1348
|
+
fireEvent.click(rendered.getByRole('button', { name: /rerender/i }))
|
|
1349
|
+
|
|
1350
|
+
// no increase because just a re-render
|
|
1351
|
+
expect(spy).toHaveBeenCalledTimes(3)
|
|
1352
|
+
|
|
1353
|
+
value = 1
|
|
1354
|
+
|
|
1355
|
+
await client.refetchQueries()
|
|
1356
|
+
|
|
1357
|
+
await waitFor(() =>
|
|
1358
|
+
rendered.getByText('data: true first result:1,second result:1'),
|
|
1359
|
+
)
|
|
1360
|
+
|
|
1361
|
+
// two value changes = two re-renders
|
|
1362
|
+
expect(spy).toHaveBeenCalledTimes(5)
|
|
1363
|
+
})
|
|
1364
|
+
|
|
1365
|
+
it('should re-run combine if the functional reference changes', async () => {
|
|
1366
|
+
const key1 = queryKey()
|
|
1367
|
+
const key2 = queryKey()
|
|
1368
|
+
|
|
1369
|
+
const client = new QueryClient()
|
|
1370
|
+
|
|
1371
|
+
const spy = vi.fn()
|
|
1372
|
+
|
|
1373
|
+
function Page() {
|
|
1374
|
+
const [state, setState] = React.useState(0)
|
|
1375
|
+
const queries = useQueries(
|
|
1376
|
+
{
|
|
1377
|
+
queries: [
|
|
1378
|
+
{
|
|
1379
|
+
queryKey: [key1],
|
|
1380
|
+
queryFn: async () => {
|
|
1381
|
+
await sleep(10)
|
|
1382
|
+
return 'first result'
|
|
1383
|
+
},
|
|
1384
|
+
},
|
|
1385
|
+
{
|
|
1386
|
+
queryKey: [key2],
|
|
1387
|
+
queryFn: async () => {
|
|
1388
|
+
await sleep(20)
|
|
1389
|
+
return 'second result'
|
|
1390
|
+
},
|
|
1391
|
+
},
|
|
1392
|
+
],
|
|
1393
|
+
combine: React.useCallback(
|
|
1394
|
+
(results: Array<QueryObserverResult>) => {
|
|
1395
|
+
const result = {
|
|
1396
|
+
combined: true,
|
|
1397
|
+
state,
|
|
1398
|
+
res: results.map((res) => res.data).join(','),
|
|
1399
|
+
}
|
|
1400
|
+
spy(result)
|
|
1401
|
+
return result
|
|
1402
|
+
},
|
|
1403
|
+
[state],
|
|
1404
|
+
),
|
|
1405
|
+
},
|
|
1406
|
+
client,
|
|
1407
|
+
)
|
|
1408
|
+
|
|
1409
|
+
return (
|
|
1410
|
+
<div>
|
|
1411
|
+
<div>
|
|
1412
|
+
data: {String(queries.state)} {queries.res}
|
|
1413
|
+
</div>
|
|
1414
|
+
<button onClick={() => setState(state + 1)}>rerender</button>
|
|
1415
|
+
</div>
|
|
1416
|
+
)
|
|
1417
|
+
}
|
|
1418
|
+
|
|
1419
|
+
const rendered = render(<Page />)
|
|
1420
|
+
|
|
1421
|
+
await waitFor(() =>
|
|
1422
|
+
rendered.getByText('data: 0 first result,second result'),
|
|
1423
|
+
)
|
|
1424
|
+
|
|
1425
|
+
// both pending, one pending, both resolved
|
|
1426
|
+
expect(spy).toHaveBeenCalledTimes(3)
|
|
1427
|
+
|
|
1428
|
+
fireEvent.click(rendered.getByRole('button', { name: /rerender/i }))
|
|
1429
|
+
|
|
1430
|
+
// state changed, re-run combine
|
|
1431
|
+
expect(spy).toHaveBeenCalledTimes(4)
|
|
1432
|
+
})
|
|
1281
1433
|
})
|
|
@@ -48,14 +48,14 @@ export function infiniteQueryOptions<
|
|
|
48
48
|
TQueryKey extends QueryKey = QueryKey,
|
|
49
49
|
TPageParam = unknown,
|
|
50
50
|
>(
|
|
51
|
-
options:
|
|
51
|
+
options: DefinedInitialDataInfiniteOptions<
|
|
52
52
|
TQueryFnData,
|
|
53
53
|
TError,
|
|
54
54
|
TData,
|
|
55
55
|
TQueryKey,
|
|
56
56
|
TPageParam
|
|
57
57
|
>,
|
|
58
|
-
):
|
|
58
|
+
): DefinedInitialDataInfiniteOptions<
|
|
59
59
|
TQueryFnData,
|
|
60
60
|
TError,
|
|
61
61
|
TData,
|
|
@@ -72,14 +72,14 @@ export function infiniteQueryOptions<
|
|
|
72
72
|
TQueryKey extends QueryKey = QueryKey,
|
|
73
73
|
TPageParam = unknown,
|
|
74
74
|
>(
|
|
75
|
-
options:
|
|
75
|
+
options: UndefinedInitialDataInfiniteOptions<
|
|
76
76
|
TQueryFnData,
|
|
77
77
|
TError,
|
|
78
78
|
TData,
|
|
79
79
|
TQueryKey,
|
|
80
80
|
TPageParam
|
|
81
81
|
>,
|
|
82
|
-
):
|
|
82
|
+
): UndefinedInitialDataInfiniteOptions<
|
|
83
83
|
TQueryFnData,
|
|
84
84
|
TError,
|
|
85
85
|
TData,
|
package/src/queryOptions.ts
CHANGED
|
@@ -29,8 +29,8 @@ export function queryOptions<
|
|
|
29
29
|
TData = TQueryFnData,
|
|
30
30
|
TQueryKey extends QueryKey = QueryKey,
|
|
31
31
|
>(
|
|
32
|
-
options:
|
|
33
|
-
):
|
|
32
|
+
options: DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,
|
|
33
|
+
): DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> & {
|
|
34
34
|
queryKey: DataTag<TQueryKey, TQueryFnData>
|
|
35
35
|
}
|
|
36
36
|
|
|
@@ -40,8 +40,8 @@ export function queryOptions<
|
|
|
40
40
|
TData = TQueryFnData,
|
|
41
41
|
TQueryKey extends QueryKey = QueryKey,
|
|
42
42
|
>(
|
|
43
|
-
options:
|
|
44
|
-
):
|
|
43
|
+
options: UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,
|
|
44
|
+
): UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> & {
|
|
45
45
|
queryKey: DataTag<TQueryKey, TQueryFnData>
|
|
46
46
|
}
|
|
47
47
|
|
package/src/useInfiniteQuery.ts
CHANGED
|
@@ -25,7 +25,7 @@ export function useInfiniteQuery<
|
|
|
25
25
|
TQueryKey extends QueryKey = QueryKey,
|
|
26
26
|
TPageParam = unknown,
|
|
27
27
|
>(
|
|
28
|
-
options:
|
|
28
|
+
options: DefinedInitialDataInfiniteOptions<
|
|
29
29
|
TQueryFnData,
|
|
30
30
|
TError,
|
|
31
31
|
TData,
|
|
@@ -33,7 +33,7 @@ export function useInfiniteQuery<
|
|
|
33
33
|
TPageParam
|
|
34
34
|
>,
|
|
35
35
|
queryClient?: QueryClient,
|
|
36
|
-
):
|
|
36
|
+
): DefinedUseInfiniteQueryResult<TData, TError>
|
|
37
37
|
|
|
38
38
|
export function useInfiniteQuery<
|
|
39
39
|
TQueryFnData,
|
|
@@ -42,7 +42,7 @@ export function useInfiniteQuery<
|
|
|
42
42
|
TQueryKey extends QueryKey = QueryKey,
|
|
43
43
|
TPageParam = unknown,
|
|
44
44
|
>(
|
|
45
|
-
options:
|
|
45
|
+
options: UndefinedInitialDataInfiniteOptions<
|
|
46
46
|
TQueryFnData,
|
|
47
47
|
TError,
|
|
48
48
|
TData,
|
|
@@ -50,7 +50,7 @@ export function useInfiniteQuery<
|
|
|
50
50
|
TPageParam
|
|
51
51
|
>,
|
|
52
52
|
queryClient?: QueryClient,
|
|
53
|
-
):
|
|
53
|
+
): UseInfiniteQueryResult<TData, TError>
|
|
54
54
|
|
|
55
55
|
export function useInfiniteQuery<
|
|
56
56
|
TQueryFnData,
|
package/src/useQueries.ts
CHANGED
|
@@ -55,7 +55,7 @@ type UseQueryOptionsForUseQueries<
|
|
|
55
55
|
// Avoid TS depth-limit error in case of large array literal
|
|
56
56
|
type MAXIMUM_DEPTH = 20
|
|
57
57
|
|
|
58
|
-
type
|
|
58
|
+
type GetUseQueryOptionsForUseQueries<T> =
|
|
59
59
|
// Part 1: responsible for applying explicit type parameter to function arguments, if object { queryFnData: TQueryFnData, error: TError, data: TData }
|
|
60
60
|
T extends {
|
|
61
61
|
queryFnData: infer TQueryFnData
|
|
@@ -120,7 +120,7 @@ type GetDefinedOrUndefinedQueryResult<T, TData, TError = unknown> = T extends {
|
|
|
120
120
|
: UseQueryResult<TData, TError>
|
|
121
121
|
: UseQueryResult<TData, TError>
|
|
122
122
|
|
|
123
|
-
type
|
|
123
|
+
type GetUseQueryResult<T> =
|
|
124
124
|
// Part 1: responsible for mapping explicit type parameter to function result, if object
|
|
125
125
|
T extends { queryFnData: any; error?: infer TError; data: infer TData }
|
|
126
126
|
? GetDefinedOrUndefinedQueryResult<T, TData, TError>
|
|
@@ -165,18 +165,18 @@ type GetResults<T> =
|
|
|
165
165
|
*/
|
|
166
166
|
export type QueriesOptions<
|
|
167
167
|
T extends Array<any>,
|
|
168
|
-
|
|
168
|
+
TResults extends Array<any> = [],
|
|
169
169
|
TDepth extends ReadonlyArray<number> = [],
|
|
170
170
|
> = TDepth['length'] extends MAXIMUM_DEPTH
|
|
171
171
|
? Array<UseQueryOptionsForUseQueries>
|
|
172
172
|
: T extends []
|
|
173
173
|
? []
|
|
174
174
|
: T extends [infer Head]
|
|
175
|
-
? [...
|
|
176
|
-
: T extends [infer Head, ...infer
|
|
175
|
+
? [...TResults, GetUseQueryOptionsForUseQueries<Head>]
|
|
176
|
+
: T extends [infer Head, ...infer Tails]
|
|
177
177
|
? QueriesOptions<
|
|
178
|
-
[...
|
|
179
|
-
[...
|
|
178
|
+
[...Tails],
|
|
179
|
+
[...TResults, GetUseQueryOptionsForUseQueries<Head>],
|
|
180
180
|
[...TDepth, 1]
|
|
181
181
|
>
|
|
182
182
|
: ReadonlyArray<unknown> extends T
|
|
@@ -207,18 +207,18 @@ export type QueriesOptions<
|
|
|
207
207
|
*/
|
|
208
208
|
export type QueriesResults<
|
|
209
209
|
T extends Array<any>,
|
|
210
|
-
|
|
210
|
+
TResults extends Array<any> = [],
|
|
211
211
|
TDepth extends ReadonlyArray<number> = [],
|
|
212
212
|
> = TDepth['length'] extends MAXIMUM_DEPTH
|
|
213
213
|
? Array<UseQueryResult>
|
|
214
214
|
: T extends []
|
|
215
215
|
? []
|
|
216
216
|
: T extends [infer Head]
|
|
217
|
-
? [...
|
|
218
|
-
: T extends [infer Head, ...infer
|
|
217
|
+
? [...TResults, GetUseQueryResult<Head>]
|
|
218
|
+
: T extends [infer Head, ...infer Tails]
|
|
219
219
|
? QueriesResults<
|
|
220
|
-
[...
|
|
221
|
-
[...
|
|
220
|
+
[...Tails],
|
|
221
|
+
[...TResults, GetUseQueryResult<Head>],
|
|
222
222
|
[...TDepth, 1]
|
|
223
223
|
>
|
|
224
224
|
: T extends Array<
|
package/src/useQuery.ts
CHANGED
|
@@ -18,9 +18,9 @@ export function useQuery<
|
|
|
18
18
|
TData = TQueryFnData,
|
|
19
19
|
TQueryKey extends QueryKey = QueryKey,
|
|
20
20
|
>(
|
|
21
|
-
options:
|
|
21
|
+
options: DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,
|
|
22
22
|
queryClient?: QueryClient,
|
|
23
|
-
):
|
|
23
|
+
): DefinedUseQueryResult<TData, TError>
|
|
24
24
|
|
|
25
25
|
export function useQuery<
|
|
26
26
|
TQueryFnData = unknown,
|
|
@@ -28,9 +28,9 @@ export function useQuery<
|
|
|
28
28
|
TData = TQueryFnData,
|
|
29
29
|
TQueryKey extends QueryKey = QueryKey,
|
|
30
30
|
>(
|
|
31
|
-
options:
|
|
31
|
+
options: UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,
|
|
32
32
|
queryClient?: QueryClient,
|
|
33
|
-
):
|
|
33
|
+
): UseQueryResult<TData, TError>
|
|
34
34
|
|
|
35
35
|
export function useQuery<
|
|
36
36
|
TQueryFnData = unknown,
|
|
@@ -13,7 +13,7 @@ import type {
|
|
|
13
13
|
// Avoid TS depth-limit error in case of large array literal
|
|
14
14
|
type MAXIMUM_DEPTH = 20
|
|
15
15
|
|
|
16
|
-
type
|
|
16
|
+
type GetUseSuspenseQueryOptions<T> =
|
|
17
17
|
// Part 1: responsible for applying explicit type parameter to function arguments, if object { queryFnData: TQueryFnData, error: TError, data: TData }
|
|
18
18
|
T extends {
|
|
19
19
|
queryFnData: infer TQueryFnData
|
|
@@ -61,7 +61,7 @@ type GetSuspenseOptions<T> =
|
|
|
61
61
|
: // Fallback
|
|
62
62
|
UseSuspenseQueryOptions
|
|
63
63
|
|
|
64
|
-
type
|
|
64
|
+
type GetUseSuspenseQueryResult<T> =
|
|
65
65
|
// Part 1: responsible for mapping explicit type parameter to function result, if object
|
|
66
66
|
T extends { queryFnData: any; error?: infer TError; data: infer TData }
|
|
67
67
|
? UseSuspenseQueryResult<TData, TError>
|
|
@@ -104,18 +104,18 @@ type GetSuspenseResults<T> =
|
|
|
104
104
|
*/
|
|
105
105
|
export type SuspenseQueriesOptions<
|
|
106
106
|
T extends Array<any>,
|
|
107
|
-
|
|
107
|
+
TResults extends Array<any> = [],
|
|
108
108
|
TDepth extends ReadonlyArray<number> = [],
|
|
109
109
|
> = TDepth['length'] extends MAXIMUM_DEPTH
|
|
110
110
|
? Array<UseSuspenseQueryOptions>
|
|
111
111
|
: T extends []
|
|
112
112
|
? []
|
|
113
113
|
: T extends [infer Head]
|
|
114
|
-
? [...
|
|
115
|
-
: T extends [infer Head, ...infer
|
|
114
|
+
? [...TResults, GetUseSuspenseQueryOptions<Head>]
|
|
115
|
+
: T extends [infer Head, ...infer Tails]
|
|
116
116
|
? SuspenseQueriesOptions<
|
|
117
|
-
[...
|
|
118
|
-
[...
|
|
117
|
+
[...Tails],
|
|
118
|
+
[...TResults, GetUseSuspenseQueryOptions<Head>],
|
|
119
119
|
[...TDepth, 1]
|
|
120
120
|
>
|
|
121
121
|
: Array<unknown> extends T
|
|
@@ -141,18 +141,18 @@ export type SuspenseQueriesOptions<
|
|
|
141
141
|
*/
|
|
142
142
|
export type SuspenseQueriesResults<
|
|
143
143
|
T extends Array<any>,
|
|
144
|
-
|
|
144
|
+
TResults extends Array<any> = [],
|
|
145
145
|
TDepth extends ReadonlyArray<number> = [],
|
|
146
146
|
> = TDepth['length'] extends MAXIMUM_DEPTH
|
|
147
147
|
? Array<UseSuspenseQueryResult>
|
|
148
148
|
: T extends []
|
|
149
149
|
? []
|
|
150
150
|
: T extends [infer Head]
|
|
151
|
-
? [...
|
|
152
|
-
: T extends [infer Head, ...infer
|
|
151
|
+
? [...TResults, GetUseSuspenseQueryResult<Head>]
|
|
152
|
+
: T extends [infer Head, ...infer Tails]
|
|
153
153
|
? SuspenseQueriesResults<
|
|
154
|
-
[...
|
|
155
|
-
[...
|
|
154
|
+
[...Tails],
|
|
155
|
+
[...TResults, GetUseSuspenseQueryResult<Head>],
|
|
156
156
|
[...TDepth, 1]
|
|
157
157
|
>
|
|
158
158
|
: T extends Array<
|