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(types): error booleans shouldn't permanently be typed as false #7956

Merged
merged 4 commits into from
Aug 26, 2024
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
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
Loading