Skip to content

Commit

Permalink
fix(types): error booleans shouldn't permanently be typed as false (#…
Browse files Browse the repository at this point in the history
…7956)

* fix(types): error booleans shouldn't permanently be typed as `false`

* fix(types): error booleans shouldn't permanently be typed as `false`

* chore: I don't understand these errors
  • Loading branch information
TkDodo authored Aug 26, 2024
1 parent 8cf7e2f commit b93941d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ describe('InfiniteQueryObserver', () => {
expectTypeOf(result.data).toEqualTypeOf<InfiniteData<string, unknown>>()
expectTypeOf(result.error).toEqualTypeOf<Error>()
expectTypeOf(result.status).toEqualTypeOf<'error'>()
expectTypeOf(result.isFetchNextPageError).toEqualTypeOf<false>()
expectTypeOf(result.isFetchPreviousPageError).toEqualTypeOf<false>()
expectTypeOf(result.isFetchNextPageError).toEqualTypeOf<boolean>()
expectTypeOf(result.isFetchPreviousPageError).toEqualTypeOf<boolean>()
}

if (result.isSuccess) {
Expand Down
2 changes: 0 additions & 2 deletions packages/query-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -853,8 +853,6 @@ export interface InfiniteQueryObserverRefetchErrorResult<
isLoading: false
isLoadingError: false
isRefetchError: true
isFetchNextPageError: false
isFetchPreviousPageError: false
isSuccess: false
status: 'error'
}
Expand Down
23 changes: 23 additions & 0 deletions packages/react-query/src/__tests__/useInfiniteQuery.test-d.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,26 @@ describe('getNextPageParam / getPreviousPageParam', () => {
>()
})
})

describe('error booleans', () => {
it('should not be permanently `false`', () => {
const {
isFetchNextPageError,
isFetchPreviousPageError,
isLoadingError,
isRefetchError,
} = useInfiniteQuery({
queryKey: ['key'],
queryFn: ({ pageParam }) => {
return pageParam * 5
},
initialPageParam: 1,
getNextPageParam: () => undefined,
})

expectTypeOf(isFetchNextPageError).toEqualTypeOf<boolean>()
expectTypeOf(isFetchPreviousPageError).toEqualTypeOf<boolean>()
expectTypeOf(isLoadingError).toEqualTypeOf<boolean>()
expectTypeOf(isRefetchError).toEqualTypeOf<boolean>()
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,7 @@ describe('useInfiniteQuery', () => {
const states: Array<
Partial<CreateInfiniteQueryResult<InfiniteData<number>>>
> = []

let isRefetch = false

function Page() {
Expand Down Expand Up @@ -717,7 +718,7 @@ describe('useInfiniteQuery', () => {
isFetchingNextPage: state.isFetchingNextPage,
isFetchPreviousPageError: state.isFetchPreviousPageError,
isFetchingPreviousPage: state.isFetchingPreviousPage,
isRefetchError: state.isRefetchError,
isRefetchError: state.isRefetchError as true,
isRefetching: state.isRefetching,
})
})
Expand Down Expand Up @@ -828,7 +829,7 @@ describe('useInfiniteQuery', () => {
isFetchingNextPage: state.isFetchingNextPage,
isFetchPreviousPageError: state.isFetchPreviousPageError,
isFetchingPreviousPage: state.isFetchingPreviousPage,
isRefetchError: state.isRefetchError,
isRefetchError: state.isRefetchError as true,
isRefetching: state.isRefetching,
})
})
Expand Down Expand Up @@ -932,7 +933,7 @@ describe('useInfiniteQuery', () => {
isFetchingNextPage: state.isFetchingNextPage,
isFetchPreviousPageError: state.isFetchPreviousPageError,
isFetchingPreviousPage: state.isFetchingPreviousPage,
isRefetchError: state.isRefetchError,
isRefetchError: state.isRefetchError as true,
isRefetching: state.isRefetching,
})
})
Expand Down

0 comments on commit b93941d

Please sign in to comment.