Repository: tanstack/query
File: packages/query-core/src/__tests__/queryClient.test-d.tsx (TypeScript)

Code before:
    const mutationKey = mutationOptions.mutationKey!

    //
    // Method type tests
    //

    const state = queryClient.getQueryState(queryKey)
    expectTypeOf(state).toEqualTypeOf<QueryState<TData, TError> | undefined>()

    const queryData1 = queryClient.getQueryData(queryKey)
    expectTypeOf(queryData1).toEqualTypeOf<TData | undefined>()

    const queryData2 = await queryClient.ensureQueryData(queryOptions)
    expectTypeOf(queryData2).toEqualTypeOf<TData>()

    const queriesData = queryClient.getQueriesData(queryFilters)
    expectTypeOf(queriesData).toEqualTypeOf<
      Array<[QueryKey, TData | undefined]>
    >()

    const queryData3 = queryClient.setQueryData(queryKey, { foo: '' })
    type SetQueryDataUpdaterArg = Parameters<
      typeof queryClient.setQueryData<unknown, typeof queryKey>
    >[1]

    expectTypeOf(null as unknown as SetQueryDataUpdaterArg).toEqualTypeOf<
      Updater<TData | undefined, TData | undefined>
    >()
    expectTypeOf(queryData3).toEqualTypeOf<TData | undefined>()

    const queriesData2 = queryClient.setQueriesData(queryFilters, { foo: '' }) // TODO: types here are wrong and coming up undefined
    type SetQueriesDataUpdaterArg = Parameters<
      typeof queryClient.setQueriesData<unknown, typeof queryFilters>
    >[1]

    expectTypeOf(null as any as SetQueriesDataUpdaterArg).toEqualTypeOf<
      Updater<TData | undefined, TData | undefined>
    >()
    expectTypeOf(queriesData2).toEqualTypeOf<
      Array<[QueryKey, TData | undefined]>
    >()

    const queryState = queryClient.getQueryState(queryKey)
    expectTypeOf(queryState).toEqualTypeOf<
      QueryState<TData, TError> | undefined
    >()

    const fetchedQuery = await queryClient.fetchQuery(queryOptions)
    expectTypeOf(fetchedQuery).toEqualTypeOf<TData>()

    queryClient.prefetchQuery(queryOptions)

Review comment (suggestion):
`expectTypeOf<SetQeuey...>().toEqualTypeOf<Updater...>()`

Code after:
    const mutationKey = mutationOptions.mutationKey!

    //
    // Method type tests
    //

    const state = queryClient.getQueryState(queryKey)
    expectTypeOf(state).toEqualTypeOf<QueryState<TData, TError> | undefined>()

    const queryData1 = queryClient.getQueryData(queryKey)
    expectTypeOf(queryData1).toEqualTypeOf<TData | undefined>()

    const queryData2 = await queryClient.ensureQueryData(queryOptions)
    expectTypeOf(queryData2).toEqualTypeOf<TData>()

    const queriesData = queryClient.getQueriesData(queryFilters)
    expectTypeOf(queriesData).toEqualTypeOf<
      Array<[QueryKey, TData | undefined]>
    >()

    const queryData3 = queryClient.setQueryData(queryKey, { foo: '' })
    type SetQueryDataUpdaterArg = Parameters<
      typeof queryClient.setQueryData<unknown, typeof queryKey>
    >[1]

    expectTypeOf<SetQueryDataUpdaterArg>().toEqualTypeOf<
      Updater<TData | undefined, TData | undefined>
    >()
    expectTypeOf(queryData3).toEqualTypeOf<TData | undefined>()

    const queriesData2 = queryClient.setQueriesData(queryFilters, { foo: '' }) // TODO: types here are wrong and coming up undefined
    type SetQueriesDataUpdaterArg = Parameters<
      typeof queryClient.setQueriesData<unknown, typeof queryFilters>
    >[1]

    expectTypeOf<SetQueriesDataUpdaterArg>().toEqualTypeOf<
      Updater<TData | undefined, TData | undefined>
    >()
    expectTypeOf(queriesData2).toEqualTypeOf<
      Array<[QueryKey, TData | undefined]>
    >()

    const queryState = queryClient.getQueryState(queryKey)
    expectTypeOf(queryState).toEqualTypeOf<
      QueryState<TData, TError> | undefined
    >()

    const fetchedQuery = await queryClient.fetchQuery(queryOptions)
    expectTypeOf(fetchedQuery).toEqualTypeOf<TData>()

    queryClient.prefetchQuery(queryOptions)