Repository: tannerlinsley/react-query (ts)

Issue:
InfiniteQueryResult Type - data can be undefined
**Describe the bug**
Until the first page is loaded, data is undefined eventhough data is typed as `data: TResult[]`

**Expected behavior**
data is typed as `data: TResult[] | undefined`

Pull request description:
fix: include undefined in IniniteQueryResult data type
fixes #737 
Let me know if it needs more work. 

Patch:
diff --git a/types/index.d.ts b/types/index.d.ts
index 5d7798b1b..8902410fe 100644
--- a/types/index.d.ts
+++ b/types/index.d.ts
@@ -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: (


Test patch:
diff --git a/types/test.ts b/types/test.ts
index 630911b08..f9184dcdd 100644
--- a/types/test.ts
+++ b/types/test.ts
@@ -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
@@ -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 (
@@ -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 (
@@ -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[]) {}