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

More infinite query missing types #4875

Closed
markerikson opened this issue Mar 4, 2025 · 0 comments · Fixed by #4880
Closed

More infinite query missing types #4875

markerikson opened this issue Mar 4, 2025 · 0 comments · Fixed by #4880

Comments

@markerikson
Copy link
Collaborator

Pessimistic Updates with infiniteQuery Not Working (selectCachedArgsForQuery Issue)

Description

I'm trying to use selectCachedArgsForQuery with an infiniteQuery in RTK Query, but I get a TypeScript error:

Argument of type '"getApplications"' is not assignable to parameter of type 'QueryKeys<{ getApplications: InfiniteQueryDefinition<...>; ... }>'.ts(2345)

I suspect that selectCachedArgsForQuery does not support infiniteQuery, and there is no equivalent function like selectCachedArgsForInfiniteQuery.

Code Example

async onQueryStarted(productId, _api) {
  const { dispatch, queryFulfilled } = _api;
  const state = _api.getState();

  try {
    await queryFulfilled;

    const args = applicationApi.util.selectCachedArgsForQuery(
      state,
      "getApplications", // Infinite query
    );

    args.forEach((arg) => {
      dispatch(
        applicationApi.util.updateQueryData(
          "getApplications",
          arg,
          (prevData) => prevData, // No modification, just checking structure
        ),
      );
    });
  } catch (error) {
    console.error(error);
  }
}

Expected Behavior

  • selectCachedArgsForQuery should return the correct cached arguments for an infiniteQuery.
  • If selectCachedArgsForQuery does not support infiniteQuery, an alternative method (e.g., selectCachedArgsForInfiniteQuery) should be provided.

Observed Behavior

  • TypeScript throws an error that "getApplications" is not assignable to the expected type.
  • There is no documented way to get cached arguments for infiniteQuery.

Possible Fixes

  • Add support for selecting cached arguments from infiniteQuery.
  • Provide a utility function like selectCachedArgsForInfiniteQuery.
  • Improve documentation to clarify how to manually retrieve cached arguments for infiniteQuery.

Originally posted by @User6531 in #4858 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant