Skip to content

Missing fetchNextPage and fetchPreviousPage from TypedUseInfiniteQueryHookResult type #5162

@bwlt

Description

@bwlt

Hello! I'm using RTK with TypeScript.
I found this useful helper: TypedUseQueryHookResult with description:

/**
  * Helper type to manually type the result
  * of the `useQuery` hook in userland code.
  */
type TypedUseQueryHookResult<...> = ...

(source)

I can find many Typed* helpers, including TypedUseInfiniteQueryHookResult.
This last specific type has some issues:

  • it doesn't have the jsdoc like the other helper types (maybe it's not ready?)
  • it's missing of the fields fetchNextPage and fetchPreviousPage

A workaround in userland for the second point (missing fields) is something like this:

import type {
  BaseQueryFn,
  TypedUseInfiniteQueryHookResult,
  TypedUseInfiniteQuerySubscriptionResult,
} from '@reduxjs/toolkit/query/react';

export type MyComponentProps = {
  query: TypedUseInfiniteQueryHookResult<MyResultType, unknown, unknown, BaseQueryFn> &
    Pick<
      TypedUseInfiniteQuerySubscriptionResult<
        MyResultType,
        unknown,
        unknown,
        BaseQueryFn
      >,
      'fetchNextPage' | 'fetchPreviousPage'
    >;
};

Which is similar to the pattern on lines 1002-1005

Would be great to have this enhancement available in the library. What do you think?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions