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: include undefined in IniniteQueryResult data type #738

Merged
merged 2 commits into from
Jul 11, 2020
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 types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ export type PaginatedQueryResult<TResult, TError = Error> =

export interface InfiniteQueryResult<TResult, TMoreVariable, TError = Error>
extends QueryResultBase<TResult[], TError> {
data: TResult[]
data: TResult[] | undefined
isFetchingMore: false | 'previous' | 'next'
canFetchMore: boolean | undefined
fetchMore: (
Expand Down
14 changes: 7 additions & 7 deletions types/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ function simpleInfiniteQuery(condition: boolean) {
// getFetchMore: (last, all) => 'string',
// });

infiniteQuery.data // $ExpectType number[][]
infiniteQuery.data // $ExpectType number[][] | undefined
infiniteQuery.fetchMore() // $ExpectType Promise<number[][]> | undefined
infiniteQuery.fetchMore('next') // $ExpectType Promise<number[][]> | undefined
infiniteQuery.fetchMore('next', { previous: true }) // $ExpectType Promise<number[][]> | undefined
Expand All @@ -352,14 +352,14 @@ function infiniteQueryWithObjectSyntax() {
config: {
getFetchMore: (last: { next: number }) => last.next, // annotation on this type is required to infer the type
},
}).data // $ExpectType { next: number; }[]
}).data // $ExpectType { next: number; }[] | undefined
useInfiniteQuery({
queryKey: ['key', 1],
queryFn: async (key, id, next = 0) => ({ next: next + 1 }),
config: {
getFetchMore: (last: { next: number }) => last.next, // annotation on this type is required to infer the type
},
}).data // $ExpectType { next: number; }[]
}).data // $ExpectType { next: number; }[] | undefined
useInfiniteQuery({
queryKey: 'key',
queryFn: async (
Expand All @@ -369,7 +369,7 @@ function infiniteQueryWithObjectSyntax() {
config: {
getFetchMore: (last: { next: number }) => last.next, // annotation on this type is required to infer the type
},
}).data // $ExpectType { next: number; }[]
}).data // $ExpectType { next: number; }[] | undefined
useInfiniteQuery({
queryKey: 'key',
queryFn: async (
Expand All @@ -379,15 +379,15 @@ function infiniteQueryWithObjectSyntax() {
config: {
getFetchMore: (last: { next: number }) => last.next, // annotation on this type is required to infer the type
},
}).data // $ExpectType { next: number; }[]
}).data // $ExpectType { next: number; }[] | undefined

useInfiniteQuery<{ next: number }, string, undefined>({
queryKey: 'key',
}).data // $ExpectType { next: number; }[]
}).data // $ExpectType { next: number; }[] | undefined

useInfiniteQuery<{ next: number }, [string], undefined>({
queryKey: ['key'],
}).data // $ExpectType { next: number; }[]
}).data // $ExpectType { next: number; }[] | undefined
}

function log(...args: any[]) {}
Expand Down