Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(query-core): widen QueriesObserver queries type (#7446) #7492

Merged
merged 4 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, any>>,
_options?: QueriesObserverOptions<TCombinedResult>,
) {
super()
Expand Down
21 changes: 20 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,15 @@
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 +175,17 @@ 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>>
>()
})
})
Loading