Skip to content

Commit

Permalink
fix(query-core): widen QueriesObserver queries type (#7446)
Browse files Browse the repository at this point in the history
Widen the `QueriesObserver` queries type so we can assign `UseQueryOptions` to `QueryObserverOptions`.

The result from the `queryOptions` helper can now be passed to `QueriesObserver`.
  • Loading branch information
Yannick CROISSANT committed Jun 7, 2024
1 parent b0c09aa commit 8f74190
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/query-core/src/queriesObserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class QueriesObserver<

constructor(
client: QueryClient,
queries: Array<QueryObserverOptions>,
queries: Array<QueryObserverOptions<any, any, any, any>>,
_options?: QueriesObserverOptions<TCombinedResult>,
) {
super()
Expand Down
14 changes: 13 additions & 1 deletion packages/react-query/src/__tests__/queryOptions.test-d.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { describe, expect, expectTypeOf, it } from 'vitest'
import { QueryClient, dataTagSymbol, skipToken } from '@tanstack/query-core'
import { QueriesObserver, QueryClient, dataTagSymbol, skipToken } from '@tanstack/query-core'
import { queryOptions } from '../queryOptions'
import { useQuery } from '../useQuery'
import { useQueries } from '../useQueries'
import { useSuspenseQuery } from '../useSuspenseQuery'
import type { QueryObserverResult } from '@tanstack/query-core';

describe('queryOptions', () => {
it('should not allow excess properties', () => {
Expand Down Expand Up @@ -169,4 +170,15 @@ describe('queryOptions', () => {
const data = queryClient.getQueryData(options.queryKey)
expectTypeOf(data).toEqualTypeOf<unknown>()
})

it('should return the proper type when passed to QueriesObserver', () => {
const options = queryOptions({
queryKey: ['key'],
queryFn: () => Promise.resolve(5),
})

const queryClient = new QueryClient()
const queriesObserver = new QueriesObserver(queryClient, [options])
expectTypeOf(queriesObserver).toEqualTypeOf<QueriesObserver<Array<QueryObserverResult>>>()
})
})

0 comments on commit 8f74190

Please sign in to comment.