Skip to content

The auto-complete feature on useQuery did not work as expected #7209

Description

@ienrum

Describe the bug

When I use the useQuery hook and provide it with initialData, the autocomplete feature doesn't work.

Your minimal, reproducible example

https://www.typescriptlang.org/ko/play?#code/JYWwDg9gTgLgBAbzgVwM4FMCKz1QJ5wC+cAZlBCHAOQACMAhgHaoMDGA1gPRTr2swBaAI458VANwAoScEYxcJPujgAVALJ4AIvQaJJcOABMd9VAC49Bg8EMXGyEACNcUg4SmFprCM3hp0AKIAHvTgADZYogQAvHAAFACUcNEAfJZw3r6IRiYW6CHh6Nq6xLH+2Lh4ADzqWiYpcQj6ViKVANLoeBYA2lQgeALsnVQAugA0zQat+ABijBaJyWmNk1bGDObZNhYAjEQTVkQJB1aywDDA9GHF9BZNhwbrpnerh9twOwBMJ4eEP-vNQgJKTNHgwZBQRhwfKhMARG4eEH5SCwIzoRTIMJ+DDBWERCr4KRAA

Steps to reproduce

  1. Use useQuery hooks
  2. Provide initialData option
  3. Auto-complete not working when provided

Expected behavior

it should be auto-completed.

How often does this bug happen?

Every time

Screenshots or Videos

image

Platform

  • Os: Windows
  • Browser: 123.0.6312.86

Tanstack Query adapter

react-query

TanStack Query version

^5.18.1

TypeScript version

5.3.3

Additional context

I suggest just reordering the useQuery function declarations and specifying that DefinedInitialDataOptions is higher order than UnDefinedInitialDataOptions in the options declaration.

like this

export function useQuery<
  TQueryFnData = unknown,
  TError = DefaultError,
  TData = TQueryFnData,
  TQueryKey extends QueryKey = QueryKey,
>(
  options: DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,
  queryClient?: QueryClient,
): DefinedUseQueryResult<TData, TError>

export function useQuery<
  TQueryFnData = unknown,
  TError = DefaultError,
  TData = TQueryFnData,
  TQueryKey extends QueryKey = QueryKey,
>(
  options: UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,
  queryClient?: QueryClient,
): UseQueryResult<TData, TError>

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions