Skip to content

Commit

Permalink
fix(types): make sure queryOptions are passable to UseQueryOptions (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
TkDodo authored Nov 20, 2024
1 parent 6a9edbf commit 3fa4b7c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
14 changes: 14 additions & 0 deletions packages/react-query/src/__tests__/queryOptions.test-d.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { queryOptions } from '../queryOptions'
import { useQuery } from '../useQuery'
import { useQueries } from '../useQueries'
import { useSuspenseQuery } from '../useSuspenseQuery'
import type { UseQueryOptions } from '../types'
import type {
InitialDataFunction,
QueryObserverResult,
Expand Down Expand Up @@ -233,4 +234,17 @@ describe('queryOptions', () => {
testFn('id')
testFn()
})

it('should be passable to UseQueryOptions', () => {
function somethingWithQueryOptions(options: UseQueryOptions<number>) {
return options.queryKey
}

const options = queryOptions({
queryKey: ['key'],
queryFn: () => Promise.resolve(1),
})

somethingWithQueryOptions(options)
})
})
8 changes: 4 additions & 4 deletions packages/react-query/src/queryOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ export function queryOptions<
TQueryKey extends QueryKey = QueryKey,
>(
options: DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,
): DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> & {
queryKey: DataTag<TQueryKey, TQueryFnData>
): DefinedInitialDataOptions<TQueryFnData, TError, TData> & {
queryKey: DataTag<QueryKey, TQueryFnData>
}

export function queryOptions<
Expand All @@ -66,8 +66,8 @@ export function queryOptions<
TQueryKey extends QueryKey = QueryKey,
>(
options: UnusedSkipTokenOptions<TQueryFnData, TError, TData, TQueryKey>,
): UnusedSkipTokenOptions<TQueryFnData, TError, TData, TQueryKey> & {
queryKey: DataTag<TQueryKey, TQueryFnData>
): UnusedSkipTokenOptions<TQueryFnData, TError, TData> & {
queryKey: DataTag<QueryKey, TQueryFnData>
}

export function queryOptions<
Expand Down

0 comments on commit 3fa4b7c

Please sign in to comment.