Skip to content

Commit

Permalink
fix: include undefined in IniniteQueryResult data type (#738)
Browse files Browse the repository at this point in the history
* fix: include undefined in IniniteQueryResult data type

* fix: dtslint

Co-authored-by: Benedikt <benedikt.viebahn@bringmeister.de>
  • Loading branch information
bviebahn and Benedikt committed Jul 11, 2020
1 parent 119fe8c commit 52ce234
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
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

1 comment on commit 52ce234

@vercel
Copy link

@vercel vercel bot commented on 52ce234 Jul 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.