query-key-factory icon indicating copy to clipboard operation
query-key-factory copied to clipboard

Property 'pageParam' does not exist on type '{ queryKey: QueryKey; signal: AbortSignal; meta: Record<string, unknown> | undefined;

Open jerrynim opened this issue 1 year ago • 6 comments
trafficstars

Hi I'm trying to use createQueryKeys with useInfiniteQuery

when use ctx.pageParam type error occurred

Error Message

Property 'pageParam' does not exist on type '{ queryKey: QueryKey; signal: AbortSignal; meta: Record<string, unknown> | undefined; }'.ts(2339)

my Code is here

  mails: (params) => ({
    queryKey: [params],
    queryFn: (ctx) =>
      getRequest({ ...params, page: ctx.pageParam }),
  }),

is there any way to use createQueryKeys with useInfiniteQuery

jerrynim avatar Apr 01 '24 06:04 jerrynim

Any updates?

AngeelVallem avatar Apr 08 '24 20:04 AngeelVallem

Also experiencing this error. I believe the type definitions of QueryKeyFactory need to be updated to have signal be optional

ahammer-sc avatar May 14 '24 17:05 ahammer-sc

I'm facing the same bug

apenab avatar Sep 02 '24 11:09 apenab

This is causing issues with other config properties (mutationKey and queryKey) when using any typed or common meta. Has anyone made any progress on investigating?

joeyfigaro avatar Sep 10 '24 17:09 joeyfigaro

I fixed the problem migrating to the latest version of RQ. the v5

apenab avatar Sep 11 '24 11:09 apenab

@apenab could you show your RQ and query-key-factory versions please?

AngeelVallem avatar Sep 17 '24 15:09 AngeelVallem

The same problem. I have latest versions @tanstack/[email protected] and @lukemorales/[email protected].

With typescript I can't use query keys factory without errors. Here is example:

const exampleQueries = createQueryKeys('example', {
  list: ({ id, ...params }: ExampleParams) => ({
    queryKey: [id, params],
    queryFn: (ctx) =>
      axios.get(`example/${id}/list`, {
        params: {
          ...params,
          page: ctx.pageParam,
        }
      }),
  }),
});

const id = '123';

useInfiniteQuery({
  queryKey: exampleQueries.list(id).queryKey,
  queryFn: exampleQueries.list(id).queryFn, // TypeScript error: Type number is not assignable to type never
  initialPageParam: 1,
  getNextPageParam: ({ page }) => (page + 1),
});

aak-lear avatar Feb 18 '25 16:02 aak-lear