Skip to content

UseQueryOptions type declaration regression, does not work for useSuspenseQuery #8258

@jaens

Description

@jaens

Describe the bug

In previous versions, useSuspenseQuery can take a UseQueryOptions<> type as a parameter.

After an upgrade, this no longer works, and instead throws a type error.

Argument of type 'UseQueryOptions<TData, TError, TVariables, TQueryKey>' is not assignable to parameter of type 'UseSuspenseQueryOptions<TData, TError, TVariables, TQueryKey>'.
  Types of property 'queryFn' are incompatible.
    Type 'unique symbol | QueryFunction<TData, TQueryKey, never> | undefined' is not assignable to type 'QueryFunction<TData, TQueryKey, never> | undefined'.
      Type 'typeof skipToken' is not assignable to type 'QueryFunction<TData, TQueryKey, never>'.ts(2345)

How is one supposed to declare the types of functions that return the return value of queryOptions?

I looked into the current type declarations, and due to the heavy overloading now going on there, this actually seems impossible to do cleanly?

Your minimal, reproducible example

not sure how this is supposed to work, the issue template does not show how to import Tanstack Query into the TypeScript playground

Steps to reproduce

export function useStandardSuspenseQuery<
    TArgs extends unknown[],
    TData,
    TError,
    TVariables,
    TQueryKey extends QueryKey,
>(fn: (api: ApiClient, ...args: TArgs) => UseQueryOptions<TData, TError, TVariables, TQueryKey>, ...args: TArgs) {
    const apiClient = useApiClient();
    return useSuspenseQuery(fn(apiClient, ...args));
}

useStandardSuspenseQuery(c => queryOptions({
    queryKey: ["test"],
    queryFn: async () => {
        return "test";
    },
}))

Expected behavior

No type error.

How often does this bug happen?

None

Screenshots or Videos

No response

Platform

TypeScript compiler

Tanstack Query adapter

React

TanStack Query version

5.59.20

TypeScript version

5.6.3

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions