Skip to content

Commit

Permalink
optional input when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
unnoq committed Dec 10, 2024
1 parent 9910285 commit e1c5c3c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/react-query/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export type QueryOptions<TInput, TOutput, TSelectData> = (undefined extends TInp
SetOptional<UndefinedInitialDataOptions<TOutput, DefaultError, TSelectData, QueryKey>, 'queryKey'>
)

export type InfiniteOptions<TInput, TOutput, TSelectData> = { input: Omit<TInput, 'cursor'> } & (
export type InfiniteOptions<TInput, TOutput, TSelectData> = (undefined extends TInput ? { input?: Omit<TInput, 'cursor'> } : { input: Omit<TInput, 'cursor'> }) & (
SetOptional<
UndefinedInitialDataInfiniteOptions<TOutput, DefaultError, TSelectData, QueryKey, InferCursor<TInput>>,
'queryKey' | (undefined extends InferCursor<TInput> ? 'initialPageParam' : never)
Expand Down
23 changes: 23 additions & 0 deletions packages/react-query/src/utils-procedure.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,29 @@ describe('infiniteOptions', () => {
input: {},
getNextPageParam,
})

const utils2 = createProcedureUtils({} as (input: { limit?: number, cursor: number }) => Promise<string>, [])

// @ts-expect-error initialPageParam is required
utils2.infiniteOptions({
input: {},
getNextPageParam,
})
})

it('input can be optional', () => {
const utils = createProcedureUtils({} as (input: { limit?: number, cursor?: number } | undefined) => Promise<string>, [])

utils.infiniteOptions({
getNextPageParam,
})

const utils2 = createProcedureUtils({} as (input: { limit?: number, cursor?: number }) => Promise<string>, [])

// @ts-expect-error input is required
utils2.infiniteOptions({
getNextPageParam,
})
})

it('infer correct output type', () => {
Expand Down

0 comments on commit e1c5c3c

Please sign in to comment.