Skip to content

queryFn field became required in UseInfiniteQueryOptions #8180

@ymc9

Description

@ymc9

Describe the bug

Hi,

It seems that in a recent release, the queryFn field of type UseInfiniteQueryOptions (from "@tanstack/react-query") became required (was optional in previous releases).

a991d92#diff-ac3343c834b1a6ecb51aa339ab1cf591e1f595d9edfed5ee0d0bc85fd172e66fR59

However, according to the docs, the field is only required if no default query function is defined. https://tanstack.com/query/v5/docs/framework/react/reference/useInfiniteQuery

Is this change intentional? Thanks!

Your minimal, reproducible example

https://stackblitz.com/edit/vitejs-vite-ufudqn

Steps to reproduce

  1. Open a terminal tab
  2. Run "npm run build"
  3. Notice the type checking error in "src/App.tsx"
src/App.tsx:10:28 - error TS2345: Argument of type '{ queryKey: string[]; initialPageParam: () => {}; getNextPageParam: () => {}; }' is not assignable to parameter of type 'UseSuspenseInfiniteQueryOptions<unknown, Error, InfiniteData<unknown, unknown>, unknown, string[], {}>'.
  Property 'queryFn' is missing in type '{ queryKey: string[]; initialPageParam: () => {}; getNextPageParam: () => {}; }' but required in type 'UseSuspenseInfiniteQueryOptions<unknown, Error, InfiniteData<unknown, unknown>, unknown, string[], {}>'.

 10   useSuspenseInfiniteQuery({
                               ~
 11     queryKey: ['myQuery'],
    ~~~~~~~~~~~~~~~~~~~~~~~~~~
... 
 14     //queryFn: () => ({})
    ~~~~~~~~~~~~~~~~~~~~~~~~~
 15   });

Expected behavior

Compiles successfully

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

All platforms

Tanstack Query adapter

react-query

TanStack Query version

5.59.13

TypeScript version

5.5.4

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions