query icon indicating copy to clipboard operation
query copied to clipboard

pageParam missing from default queryFn typescript definition

Open rmanibus opened this issue 1 year ago • 3 comments

Describe the bug

pageParam used to be available in the default queryFn parameter options. It is still passed (it is working correctly with //@ts-ignore), but typescript is reporting the following error when using it:

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

Your minimal, reproducible example

https://tanstack.com/

Steps to reproduce

  1. create a default query function in a typescript project
  2. try to add a pageParam parameter

Expected behavior

pageParam is present in the typescript definition

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

all

Tanstack Query adapter

react-query

TanStack Query version

5.17.12

TypeScript version

4.9.5

Additional context

No response

rmanibus avatar Jan 16 '24 02:01 rmanibus

we wanted to avoid having pageParam be available on useQuery, so it's only there on useInfiniteQuery. But yeah, that influences the global queryFn. Seems like we need to remove that conditional type. Do you want to contribute that?

TkDodo avatar Jan 20 '24 14:01 TkDodo

I can have a look yes !

rmanibus avatar Jan 24 '24 17:01 rmanibus

@TkDodo shouldn't we have two default functions instead? One for the normal query and one for the infinite one ?

rmanibus avatar Jan 24 '24 17:01 rmanibus

I'm also running into this as well :)

would be nice of course to fix/extend the typescript definition QueryFunctionContext for useInfiniteQuery to include the extra parameters it received, pageParam most important haha.

bwhitt avatar Mar 27 '24 03:03 bwhitt

@TkDodo shouldn't we have two default functions instead? One for the normal query and one for the infinite one ?

that's not possible. There is only one queryFn in defaultOptions

TkDodo avatar Mar 27 '24 10:03 TkDodo

I'm also running into this as well :)

what can we do in the meanwhile?

shanicloudinary avatar Apr 01 '24 11:04 shanicloudinary