Skip to content

How to properly type the select function for infinite queries? #9481

Closed Answered by TkDodo
todor-a asked this question in Q&A
Discussion options

You must be logged in to vote

select can’t be typed with ReturnType, because that will give you:

(property) select?: ((data: InfiniteData<{
    results: Todo[];
    nextSkip?: number;
}, number>) => InfiniteData<{
    results: Todo[];
    nextSkip?: number;
}, unknown>) | undefined

which means the type you have to return from select needs to be the same as the one the queryFn returns. You need to:

I prefer the second approach because it’s way simpler and one of the reasons we introduced queryOptions as the main abstraction for your queries is that it makes things like this easier to use.

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by todor-a
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants