@tanstack/react-query 5.25.0 → 5.26.3

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.
Files changed (39) hide show
  1. package/build/codemods/coverage/clover.xml +2 -2
  2. package/build/codemods/coverage/index.html +1 -1
  3. package/build/codemods/coverage/utils/index.html +1 -1
  4. package/build/codemods/coverage/utils/index.js.html +1 -1
  5. package/build/codemods/coverage/utils/transformers/index.html +1 -1
  6. package/build/codemods/coverage/utils/transformers/query-cache-transformer.js.html +1 -1
  7. package/build/codemods/coverage/utils/transformers/query-client-transformer.js.html +1 -1
  8. package/build/codemods/coverage/utils/transformers/use-query-like-transformer.js.html +1 -1
  9. package/build/codemods/coverage/v4/index.html +1 -1
  10. package/build/codemods/coverage/v4/key-transformation.js.html +1 -1
  11. package/build/codemods/coverage/v4/replace-import-specifier.js.html +1 -1
  12. package/build/codemods/coverage/v4/utils/replacers/index.html +1 -1
  13. package/build/codemods/coverage/v4/utils/replacers/key-replacer.js.html +1 -1
  14. package/build/codemods/coverage/v5/is-loading/index.html +1 -1
  15. package/build/codemods/coverage/v5/is-loading/is-loading.js.html +1 -1
  16. package/build/codemods/coverage/v5/keep-previous-data/index.html +1 -1
  17. package/build/codemods/coverage/v5/keep-previous-data/keep-previous-data.js.html +1 -1
  18. package/build/codemods/coverage/v5/keep-previous-data/utils/already-has-placeholder-data-property.js.html +1 -1
  19. package/build/codemods/coverage/v5/keep-previous-data/utils/index.html +1 -1
  20. package/build/codemods/coverage/v5/remove-overloads/index.html +1 -1
  21. package/build/codemods/coverage/v5/remove-overloads/remove-overloads.js.html +1 -1
  22. package/build/codemods/coverage/v5/remove-overloads/transformers/filter-aware-usage-transformer.js.html +1 -1
  23. package/build/codemods/coverage/v5/remove-overloads/transformers/index.html +1 -1
  24. package/build/codemods/coverage/v5/remove-overloads/transformers/query-fn-aware-usage-transformer.js.html +1 -1
  25. package/build/codemods/coverage/v5/remove-overloads/utils/index.html +1 -1
  26. package/build/codemods/coverage/v5/remove-overloads/utils/index.js.html +1 -1
  27. package/build/codemods/coverage/v5/remove-overloads/utils/unknown-usage-error.js.html +1 -1
  28. package/build/codemods/coverage/v5/rename-hydrate/index.html +1 -1
  29. package/build/codemods/coverage/v5/rename-hydrate/rename-hydrate.js.html +1 -1
  30. package/build/codemods/coverage/v5/rename-properties/index.html +1 -1
  31. package/build/codemods/coverage/v5/rename-properties/rename-properties.js.html +1 -1
  32. package/build/query-codemods/vite.config.ts +1 -0
  33. package/package.json +2 -2
  34. package/src/__tests__/infiniteQueryOptions.test-d.tsx +4 -10
  35. package/src/__tests__/useInfiniteQuery.test.tsx +34 -58
  36. package/src/__tests__/useMutation.test.tsx +43 -62
  37. package/src/__tests__/useQueries.test.tsx +99 -100
  38. package/src/__tests__/useQuery.test.tsx +49 -47
  39. package/src/__tests__/utils.tsx +3 -10
@@ -453,8 +453,6 @@ describe('useMutation', () => {
453
453
 
454
454
  const rendered = renderWithClient(queryClient, <Page />)
455
455
 
456
- window.dispatchEvent(new Event('offline'))
457
-
458
456
  await waitFor(() => {
459
457
  expect(
460
458
  rendered.getByText('error: null, status: idle, isPaused: false'),
@@ -471,8 +469,8 @@ describe('useMutation', () => {
471
469
 
472
470
  expect(count).toBe(0)
473
471
 
474
- onlineMock.mockRestore()
475
- window.dispatchEvent(new Event('online'))
472
+ onlineMock.mockReturnValue(true)
473
+ queryClient.getMutationCache().resumePausedMutations()
476
474
 
477
475
  await sleep(100)
478
476
 
@@ -483,6 +481,7 @@ describe('useMutation', () => {
483
481
  })
484
482
 
485
483
  expect(count).toBe(2)
484
+ onlineMock.mockRestore()
486
485
  })
487
486
 
488
487
  it('should call onMutate even if paused', async () => {
@@ -515,8 +514,6 @@ describe('useMutation', () => {
515
514
 
516
515
  await rendered.findByText('data: null, status: idle, isPaused: false')
517
516
 
518
- window.dispatchEvent(new Event('offline'))
519
-
520
517
  fireEvent.click(rendered.getByRole('button', { name: /mutate/i }))
521
518
 
522
519
  await rendered.findByText('data: null, status: pending, isPaused: true')
@@ -524,13 +521,15 @@ describe('useMutation', () => {
524
521
  expect(onMutate).toHaveBeenCalledTimes(1)
525
522
  expect(onMutate).toHaveBeenCalledWith('todo')
526
523
 
527
- onlineMock.mockRestore()
528
- window.dispatchEvent(new Event('online'))
524
+ onlineMock.mockReturnValue(true)
525
+ queryClient.getMutationCache().resumePausedMutations()
529
526
 
530
527
  await rendered.findByText('data: 1, status: success, isPaused: false')
531
528
 
532
529
  expect(onMutate).toHaveBeenCalledTimes(1)
533
530
  expect(count).toBe(1)
531
+
532
+ onlineMock.mockRestore()
534
533
  })
535
534
 
536
535
  it('should optimistically go to paused state if offline', async () => {
@@ -564,8 +563,6 @@ describe('useMutation', () => {
564
563
 
565
564
  await rendered.findByText('data: null, status: idle, isPaused: false')
566
565
 
567
- window.dispatchEvent(new Event('offline'))
568
-
569
566
  fireEvent.click(rendered.getByRole('button', { name: /mutate/i }))
570
567
 
571
568
  await rendered.findByText('data: null, status: pending, isPaused: true')
@@ -574,22 +571,25 @@ describe('useMutation', () => {
574
571
  expect(states[0]).toBe('idle, false')
575
572
  expect(states[1]).toBe('pending, true')
576
573
 
577
- onlineMock.mockRestore()
578
- window.dispatchEvent(new Event('online'))
574
+ onlineMock.mockReturnValue(true)
575
+ queryClient.getMutationCache().resumePausedMutations()
579
576
 
580
577
  await rendered.findByText('data: 1, status: success, isPaused: false')
578
+
579
+ onlineMock.mockRestore()
581
580
  })
582
581
 
583
582
  it('should be able to retry a mutation when online', async () => {
584
583
  const onlineMock = mockOnlineManagerIsOnline(false)
584
+ const key = queryKey()
585
585
 
586
586
  let count = 0
587
- const states: Array<UseMutationResult<any, any, any, any>> = []
588
587
 
589
588
  function Page() {
590
589
  const state = useMutation({
590
+ mutationKey: key,
591
591
  mutationFn: async (_text: string) => {
592
- await sleep(1)
592
+ await sleep(10)
593
593
  count++
594
594
  return count > 1
595
595
  ? Promise.resolve('data')
@@ -600,69 +600,50 @@ describe('useMutation', () => {
600
600
  networkMode: 'offlineFirst',
601
601
  })
602
602
 
603
- states.push(state)
604
-
605
- const { mutate } = state
606
-
607
- React.useEffect(() => {
608
- setActTimeout(() => {
609
- window.dispatchEvent(new Event('offline'))
610
- mutate('todo')
611
- }, 10)
612
- }, [mutate])
613
-
614
- return null
603
+ return (
604
+ <div>
605
+ <button onClick={() => state.mutate('todo')}>mutate</button>
606
+ <div>status: {state.status}</div>
607
+ <div>isPaused: {String(state.isPaused)}</div>
608
+ <div>data: {state.data ?? 'null'}</div>
609
+ </div>
610
+ )
615
611
  }
616
612
 
617
- renderWithClient(queryClient, <Page />)
618
-
619
- await sleep(50)
613
+ const rendered = renderWithClient(queryClient, <Page />)
620
614
 
621
- expect(states.length).toBe(4)
622
- expect(states[0]).toMatchObject({
623
- isPending: false,
624
- isPaused: false,
625
- failureCount: 0,
626
- failureReason: null,
627
- })
628
- expect(states[1]).toMatchObject({
629
- isPending: true,
630
- isPaused: false,
631
- failureCount: 0,
632
- failureReason: null,
633
- })
634
- expect(states[2]).toMatchObject({
635
- isPending: true,
636
- isPaused: false,
637
- failureCount: 1,
638
- failureReason: new Error('oops'),
639
- })
640
- expect(states[3]).toMatchObject({
641
- isPending: true,
615
+ await waitFor(() => rendered.getByText('status: idle'))
616
+ fireEvent.click(rendered.getByRole('button', { name: /mutate/i }))
617
+ await waitFor(() => rendered.getByText('isPaused: true'))
618
+
619
+ expect(
620
+ queryClient.getMutationCache().findAll({ mutationKey: key }).length,
621
+ ).toBe(1)
622
+ expect(
623
+ queryClient.getMutationCache().findAll({ mutationKey: key })[0]?.state,
624
+ ).toMatchObject({
625
+ status: 'pending',
642
626
  isPaused: true,
643
627
  failureCount: 1,
644
628
  failureReason: new Error('oops'),
645
629
  })
646
630
 
647
- onlineMock.mockRestore()
648
- window.dispatchEvent(new Event('online'))
631
+ onlineMock.mockReturnValue(true)
632
+ queryClient.getMutationCache().resumePausedMutations()
649
633
 
650
- await sleep(50)
634
+ await waitFor(() => rendered.getByText('data: data'))
651
635
 
652
- expect(states.length).toBe(6)
653
- expect(states[4]).toMatchObject({
654
- isPending: true,
655
- isPaused: false,
656
- failureCount: 1,
657
- failureReason: new Error('oops'),
658
- })
659
- expect(states[5]).toMatchObject({
660
- isPending: false,
636
+ expect(
637
+ queryClient.getMutationCache().findAll({ mutationKey: key })[0]?.state,
638
+ ).toMatchObject({
639
+ status: 'success',
661
640
  isPaused: false,
662
641
  failureCount: 0,
663
642
  failureReason: null,
664
643
  data: 'data',
665
644
  })
645
+
646
+ onlineMock.mockRestore()
666
647
  })
667
648
 
668
649
  it('should not change state if unmounted', async () => {
@@ -3,21 +3,14 @@ import { fireEvent, render, waitFor } from '@testing-library/react'
3
3
  import * as React from 'react'
4
4
  import { ErrorBoundary } from 'react-error-boundary'
5
5
  import { QueryCache, queryOptions, skipToken, useQueries } from '..'
6
- import {
7
- createQueryClient,
8
- expectTypeNotAny,
9
- queryKey,
10
- renderWithClient,
11
- sleep,
12
- } from './utils'
6
+ import { createQueryClient, queryKey, renderWithClient, sleep } from './utils'
13
7
  import type {
14
8
  QueryFunction,
15
9
  QueryKey,
16
- QueryObserverResult,
17
10
  UseQueryOptions,
18
11
  UseQueryResult,
19
12
  } from '..'
20
- import type { QueryFunctionContext, SkipToken } from '@tanstack/query-core'
13
+ import type { QueryFunctionContext } from '@tanstack/query-core'
21
14
 
22
15
  describe('useQueries', () => {
23
16
  const queryCache = new QueryCache()
@@ -140,13 +133,15 @@ describe('useQueries', () => {
140
133
  },
141
134
  ],
142
135
  })
143
- expectTypeOf<QueryObserverResult<number, unknown>>(result1[0])
144
- expectTypeOf<QueryObserverResult<string, unknown>>(result1[1])
145
- expectTypeOf<QueryObserverResult<Array<string>, boolean>>(result1[2])
146
- expectTypeOf<number | undefined>(result1[0].data)
147
- expectTypeOf<string | undefined>(result1[1].data)
148
- expectTypeOf<Array<string> | undefined>(result1[2].data)
149
- expectTypeOf<boolean | null>(result1[2].error)
136
+ expectTypeOf(result1[0]).toEqualTypeOf<UseQueryResult<number, unknown>>()
137
+ expectTypeOf(result1[1]).toEqualTypeOf<UseQueryResult<string, unknown>>()
138
+ expectTypeOf(result1[2]).toEqualTypeOf<
139
+ UseQueryResult<Array<string>, boolean>
140
+ >()
141
+ expectTypeOf(result1[0].data).toEqualTypeOf<number | undefined>()
142
+ expectTypeOf(result1[1].data).toEqualTypeOf<string | undefined>()
143
+ expectTypeOf(result1[2].data).toEqualTypeOf<Array<string> | undefined>()
144
+ expectTypeOf(result1[2].error).toEqualTypeOf<boolean | null>()
150
145
 
151
146
  // TData (3rd element) takes precedence over TQueryFnData (1st element)
152
147
  const result2 = useQueries<
@@ -157,8 +152,7 @@ describe('useQueries', () => {
157
152
  queryKey: key1,
158
153
  queryFn: () => 'string',
159
154
  select: (a) => {
160
- expectTypeOf<string>(a)
161
- expectTypeNotAny(a)
155
+ expectTypeOf(a).toEqualTypeOf<string>()
162
156
  return a.toLowerCase()
163
157
  },
164
158
  },
@@ -166,17 +160,16 @@ describe('useQueries', () => {
166
160
  queryKey: key2,
167
161
  queryFn: () => 'string',
168
162
  select: (a) => {
169
- expectTypeOf<string>(a)
170
- expectTypeNotAny(a)
163
+ expectTypeOf(a).toEqualTypeOf<string>()
171
164
  return parseInt(a)
172
165
  },
173
166
  },
174
167
  ],
175
168
  })
176
- expectTypeOf<QueryObserverResult<string, unknown>>(result2[0])
177
- expectTypeOf<QueryObserverResult<number, unknown>>(result2[1])
178
- expectTypeOf<string | undefined>(result2[0].data)
179
- expectTypeOf<number | undefined>(result2[1].data)
169
+ expectTypeOf(result2[0]).toEqualTypeOf<UseQueryResult<string, unknown>>()
170
+ expectTypeOf(result2[1]).toEqualTypeOf<UseQueryResult<number, unknown>>()
171
+ expectTypeOf(result2[0].data).toEqualTypeOf<string | undefined>()
172
+ expectTypeOf(result2[1].data).toEqualTypeOf<number | undefined>()
180
173
 
181
174
  // types should be enforced
182
175
  useQueries<[[string, unknown, string], [string, boolean, number]]>({
@@ -185,8 +178,7 @@ describe('useQueries', () => {
185
178
  queryKey: key1,
186
179
  queryFn: () => 'string',
187
180
  select: (a) => {
188
- expectTypeOf<string>(a)
189
- expectTypeNotAny(a)
181
+ expectTypeOf(a).toEqualTypeOf<string>()
190
182
  return a.toLowerCase()
191
183
  },
192
184
  placeholderData: 'string',
@@ -197,8 +189,7 @@ describe('useQueries', () => {
197
189
  queryKey: key2,
198
190
  queryFn: () => 'string',
199
191
  select: (a) => {
200
- expectTypeOf<string>(a)
201
- expectTypeNotAny(a)
192
+ expectTypeOf(a).toEqualTypeOf<string>()
202
193
  return parseInt(a)
203
194
  },
204
195
  placeholderData: 'string',
@@ -251,13 +242,15 @@ describe('useQueries', () => {
251
242
  },
252
243
  ],
253
244
  })
254
- expectTypeOf<QueryObserverResult<number, unknown>>(result1[0])
255
- expectTypeOf<QueryObserverResult<string, unknown>>(result1[1])
256
- expectTypeOf<QueryObserverResult<Array<string>, boolean>>(result1[2])
257
- expectTypeOf<number | undefined>(result1[0].data)
258
- expectTypeOf<string | undefined>(result1[1].data)
259
- expectTypeOf<Array<string> | undefined>(result1[2].data)
260
- expectTypeOf<boolean | null>(result1[2].error)
245
+ expectTypeOf(result1[0]).toEqualTypeOf<UseQueryResult<number, unknown>>()
246
+ expectTypeOf(result1[1]).toEqualTypeOf<UseQueryResult<string, unknown>>()
247
+ expectTypeOf(result1[2]).toEqualTypeOf<
248
+ UseQueryResult<Array<string>, boolean>
249
+ >()
250
+ expectTypeOf(result1[0].data).toEqualTypeOf<number | undefined>()
251
+ expectTypeOf(result1[1].data).toEqualTypeOf<string | undefined>()
252
+ expectTypeOf(result1[2].data).toEqualTypeOf<Array<string> | undefined>()
253
+ expectTypeOf(result1[2].error).toEqualTypeOf<boolean | null>()
261
254
 
262
255
  // TData (data prop) takes precedence over TQueryFnData (queryFnData prop)
263
256
  const result2 = useQueries<
@@ -271,8 +264,7 @@ describe('useQueries', () => {
271
264
  queryKey: key1,
272
265
  queryFn: () => 'string',
273
266
  select: (a) => {
274
- expectTypeOf<string>(a)
275
- expectTypeNotAny(a)
267
+ expectTypeOf(a).toEqualTypeOf<string>()
276
268
  return a.toLowerCase()
277
269
  },
278
270
  },
@@ -280,17 +272,16 @@ describe('useQueries', () => {
280
272
  queryKey: key2,
281
273
  queryFn: () => 'string',
282
274
  select: (a) => {
283
- expectTypeOf<string>(a)
284
- expectTypeNotAny(a)
275
+ expectTypeOf(a).toEqualTypeOf<string>()
285
276
  return parseInt(a)
286
277
  },
287
278
  },
288
279
  ],
289
280
  })
290
- expectTypeOf<QueryObserverResult<string, unknown>>(result2[0])
291
- expectTypeOf<QueryObserverResult<number, unknown>>(result2[1])
292
- expectTypeOf<string | undefined>(result2[0].data)
293
- expectTypeOf<number | undefined>(result2[1].data)
281
+ expectTypeOf(result2[0]).toEqualTypeOf<UseQueryResult<string, unknown>>()
282
+ expectTypeOf(result2[1]).toEqualTypeOf<UseQueryResult<number, unknown>>()
283
+ expectTypeOf(result2[0].data).toEqualTypeOf<string | undefined>()
284
+ expectTypeOf(result2[1].data).toEqualTypeOf<number | undefined>()
294
285
 
295
286
  // can pass only TData (data prop) although TQueryFnData will be left unknown
296
287
  const result3 = useQueries<[{ data: string }, { data: number }]>({
@@ -299,8 +290,7 @@ describe('useQueries', () => {
299
290
  queryKey: key1,
300
291
  queryFn: () => 'string',
301
292
  select: (a) => {
302
- expectTypeOf<unknown>(a)
303
- expectTypeNotAny(a)
293
+ expectTypeOf(a).toEqualTypeOf<unknown>()
304
294
  return a as string
305
295
  },
306
296
  },
@@ -308,17 +298,16 @@ describe('useQueries', () => {
308
298
  queryKey: key2,
309
299
  queryFn: () => 'string',
310
300
  select: (a) => {
311
- expectTypeOf<unknown>(a)
312
- expectTypeNotAny(a)
301
+ expectTypeOf(a).toEqualTypeOf<unknown>()
313
302
  return a as number
314
303
  },
315
304
  },
316
305
  ],
317
306
  })
318
- expectTypeOf<QueryObserverResult<string, unknown>>(result3[0])
319
- expectTypeOf<QueryObserverResult<number, unknown>>(result3[1])
320
- expectTypeOf<string | undefined>(result3[0].data)
321
- expectTypeOf<number | undefined>(result3[1].data)
307
+ expectTypeOf(result3[0]).toEqualTypeOf<UseQueryResult<string, unknown>>()
308
+ expectTypeOf(result3[1]).toEqualTypeOf<UseQueryResult<number, unknown>>()
309
+ expectTypeOf(result3[0].data).toEqualTypeOf<string | undefined>()
310
+ expectTypeOf(result3[1].data).toEqualTypeOf<number | undefined>()
322
311
 
323
312
  // types should be enforced
324
313
  useQueries<
@@ -332,8 +321,7 @@ describe('useQueries', () => {
332
321
  queryKey: key1,
333
322
  queryFn: () => 'string',
334
323
  select: (a) => {
335
- expectTypeOf<string>(a)
336
- expectTypeNotAny(a)
324
+ expectTypeOf(a).toEqualTypeOf<string>()
337
325
  return a.toLowerCase()
338
326
  },
339
327
  placeholderData: 'string',
@@ -344,8 +332,7 @@ describe('useQueries', () => {
344
332
  queryKey: key2,
345
333
  queryFn: () => 'string',
346
334
  select: (a) => {
347
- expectTypeOf<string>(a)
348
- expectTypeNotAny(a)
335
+ expectTypeOf(a).toEqualTypeOf<string>()
349
336
  return parseInt(a)
350
337
  },
351
338
  placeholderData: 'string',
@@ -379,8 +366,7 @@ describe('useQueries', () => {
379
366
  queryKey: ['key1'],
380
367
  queryFn: () => 'string',
381
368
  select: (a) => {
382
- expectTypeOf<string>(a)
383
- expectTypeNotAny(a)
369
+ expectTypeOf(a).toEqualTypeOf<string>()
384
370
  return a.toLowerCase()
385
371
  },
386
372
  }),
@@ -388,17 +374,16 @@ describe('useQueries', () => {
388
374
  queryKey: ['key2'],
389
375
  queryFn: () => 'string',
390
376
  select: (a) => {
391
- expectTypeOf<string>(a)
392
- expectTypeNotAny(a)
377
+ expectTypeOf(a).toEqualTypeOf<string>()
393
378
  return parseInt(a)
394
379
  },
395
380
  }),
396
381
  ],
397
382
  })
398
- expectTypeOf<QueryObserverResult<string, unknown>>(result4[0])
399
- expectTypeOf<QueryObserverResult<number, unknown>>(result4[1])
400
- expectTypeOf<string | undefined>(result4[0].data)
401
- expectTypeOf<number | undefined>(result4[1].data)
383
+ expectTypeOf(result4[0]).toEqualTypeOf<UseQueryResult<string, Error>>()
384
+ expectTypeOf(result4[1]).toEqualTypeOf<UseQueryResult<number, Error>>()
385
+ expectTypeOf(result4[0].data).toEqualTypeOf<string | undefined>()
386
+ expectTypeOf(result4[1].data).toEqualTypeOf<number | undefined>()
402
387
  }
403
388
  })
404
389
 
@@ -421,8 +406,12 @@ describe('useQueries', () => {
421
406
  queryFn: () => i + 10,
422
407
  })),
423
408
  })
424
- expectTypeOf<Array<QueryObserverResult<number, unknown>>>(result1)
425
- expectTypeOf<number | undefined>(result1[0]?.data)
409
+ expectTypeOf(result1).toEqualTypeOf<
410
+ Array<UseQueryResult<number, Error>>
411
+ >()
412
+ if (result1[0]) {
413
+ expectTypeOf(result1[0].data).toEqualTypeOf<number | undefined>()
414
+ }
426
415
 
427
416
  // Array.map preserves TError
428
417
  const result1_err = useQueries({
@@ -432,9 +421,13 @@ describe('useQueries', () => {
432
421
  throwOnError,
433
422
  })),
434
423
  })
435
- expectTypeOf<Array<QueryObserverResult<number, unknown>>>(result1_err)
436
- expectTypeOf<number | undefined>(result1_err[0]?.data)
437
- expectTypeOf<BizError | null | undefined>(result1_err[0]?.error)
424
+ expectTypeOf(result1_err).toEqualTypeOf<
425
+ Array<UseQueryResult<number, BizError>>
426
+ >()
427
+ if (result1_err[0]) {
428
+ expectTypeOf(result1_err[0].data).toEqualTypeOf<number | undefined>()
429
+ expectTypeOf(result1_err[0].error).toEqualTypeOf<BizError | null>()
430
+ }
438
431
 
439
432
  // Array.map preserves TData
440
433
  const result2 = useQueries({
@@ -444,7 +437,9 @@ describe('useQueries', () => {
444
437
  select: (data: number) => data.toString(),
445
438
  })),
446
439
  })
447
- expectTypeOf<Array<QueryObserverResult<string, unknown>>>(result2)
440
+ expectTypeOf(result2).toEqualTypeOf<
441
+ Array<UseQueryResult<string, Error>>
442
+ >()
448
443
 
449
444
  const result2_err = useQueries({
450
445
  queries: Array(50).map((_, i) => ({
@@ -454,7 +449,9 @@ describe('useQueries', () => {
454
449
  throwOnError,
455
450
  })),
456
451
  })
457
- expectTypeOf<Array<QueryObserverResult<string, BizError>>>(result2_err)
452
+ expectTypeOf(result2_err).toEqualTypeOf<
453
+ Array<UseQueryResult<string, BizError>>
454
+ >()
458
455
 
459
456
  const result3 = useQueries({
460
457
  queries: [
@@ -478,16 +475,16 @@ describe('useQueries', () => {
478
475
  },
479
476
  ],
480
477
  })
481
- expectTypeOf<QueryObserverResult<number, unknown>>(result3[0])
482
- expectTypeOf<QueryObserverResult<string, unknown>>(result3[1])
483
- expectTypeOf<QueryObserverResult<number, unknown>>(result3[2])
484
- expectTypeOf<number | undefined>(result3[0].data)
485
- expectTypeOf<string | undefined>(result3[1].data)
486
- expectTypeOf<string | undefined>(result3[3].data)
478
+ expectTypeOf(result3[0]).toEqualTypeOf<UseQueryResult<number, Error>>()
479
+ expectTypeOf(result3[1]).toEqualTypeOf<UseQueryResult<string, Error>>()
480
+ expectTypeOf(result3[2]).toEqualTypeOf<UseQueryResult<number, Error>>()
481
+ expectTypeOf(result3[0].data).toEqualTypeOf<number | undefined>()
482
+ expectTypeOf(result3[1].data).toEqualTypeOf<string | undefined>()
483
+ expectTypeOf(result3[3].data).toEqualTypeOf<string | undefined>()
487
484
  // select takes precedence over queryFn
488
- expectTypeOf<number | undefined>(result3[2].data)
485
+ expectTypeOf(result3[2].data).toEqualTypeOf<number | undefined>()
489
486
  // infer TError from throwOnError
490
- expectTypeOf<BizError | null | undefined>(result3[3].error)
487
+ expectTypeOf(result3[3].error).toEqualTypeOf<BizError | null>()
491
488
 
492
489
  // initialData/placeholderData are enforced
493
490
  useQueries({
@@ -580,10 +577,10 @@ describe('useQueries', () => {
580
577
  },
581
578
  ],
582
579
  })
583
- expectTypeOf<QueryObserverResult<string, unknown>>(result4[0])
584
- expectTypeOf<QueryObserverResult<string, unknown>>(result4[1])
585
- expectTypeOf<QueryObserverResult<number, unknown>>(result4[2])
586
- expectTypeOf<QueryObserverResult<number, BizError>>(result4[3])
580
+ expectTypeOf(result4[0]).toEqualTypeOf<UseQueryResult<string, Error>>()
581
+ expectTypeOf(result4[1]).toEqualTypeOf<UseQueryResult<string, Error>>()
582
+ expectTypeOf(result4[2]).toEqualTypeOf<UseQueryResult<number, Error>>()
583
+ expectTypeOf(result4[3]).toEqualTypeOf<UseQueryResult<number, BizError>>()
587
584
 
588
585
  // handles when queryFn returns a Promise
589
586
  const result5 = useQueries({
@@ -594,7 +591,7 @@ describe('useQueries', () => {
594
591
  },
595
592
  ],
596
593
  })
597
- expectTypeOf<QueryObserverResult<string, unknown>>(result5[0])
594
+ expectTypeOf(result5[0]).toEqualTypeOf<UseQueryResult<string, Error>>()
598
595
 
599
596
  // Array as const does not throw error
600
597
  const result6 = useQueries({
@@ -614,9 +611,9 @@ describe('useQueries', () => {
614
611
  },
615
612
  ],
616
613
  } as const)
617
- expectTypeOf<QueryObserverResult<string, unknown>>(result6[0])
618
- expectTypeOf<QueryObserverResult<number, unknown>>(result6[1])
619
- expectTypeOf<QueryObserverResult<string, BizError>>(result6[2])
614
+ expectTypeOf(result6[0]).toEqualTypeOf<UseQueryResult<string, Error>>()
615
+ expectTypeOf(result6[1]).toEqualTypeOf<UseQueryResult<number, Error>>()
616
+ expectTypeOf(result6[2]).toEqualTypeOf<UseQueryResult<string, BizError>>()
620
617
 
621
618
  // field names should be enforced - array literal
622
619
  useQueries({
@@ -704,9 +701,11 @@ describe('useQueries', () => {
704
701
  // no need to type the mapped query
705
702
  (query) => {
706
703
  const { queryFn: fn, queryKey: key } = query
707
- expectTypeOf<
708
- QueryFunction<TQueryFnData, TQueryKey> | undefined | SkipToken
709
- >(fn)
704
+ expectTypeOf(fn).toEqualTypeOf<
705
+ | typeof skipToken
706
+ | QueryFunction<TQueryFnData, TQueryKey, never>
707
+ | undefined
708
+ >()
710
709
  return {
711
710
  queryKey: key,
712
711
  queryFn:
@@ -736,8 +735,8 @@ describe('useQueries', () => {
736
735
  },
737
736
  ],
738
737
  })
739
- expectTypeOf<QueryObserverResult<number, unknown>>(result[0])
740
- expectTypeOf<QueryObserverResult<string, unknown>>(result[1])
738
+ expectTypeOf(result[0]).toEqualTypeOf<UseQueryResult<number, Error>>()
739
+ expectTypeOf(result[1]).toEqualTypeOf<UseQueryResult<string, Error>>()
741
740
 
742
741
  const withSelector = useQueries({
743
742
  queries: [
@@ -753,12 +752,12 @@ describe('useQueries', () => {
753
752
  },
754
753
  ],
755
754
  })
756
- expectTypeOf<QueryObserverResult<[number, string], unknown>>(
757
- withSelector[0],
758
- )
759
- expectTypeOf<QueryObserverResult<[string, number], unknown>>(
760
- withSelector[1],
761
- )
755
+ expectTypeOf(withSelector[0]).toEqualTypeOf<
756
+ UseQueryResult<[number, string], Error>
757
+ >()
758
+ expectTypeOf(withSelector[1]).toEqualTypeOf<
759
+ UseQueryResult<[string, number], Error>
760
+ >()
762
761
 
763
762
  const withWrappedQueries = useWrappedQueries(
764
763
  Array(10).map(() => ({
@@ -768,9 +767,9 @@ describe('useQueries', () => {
768
767
  })),
769
768
  )
770
769
 
771
- expectTypeOf<Array<QueryObserverResult<number | undefined, unknown>>>(
772
- withWrappedQueries,
773
- )
770
+ expectTypeOf(withWrappedQueries).toEqualTypeOf<
771
+ Array<UseQueryResult<number, Error>>
772
+ >()
774
773
  }
775
774
  })
776
775