Skip to content

vue-query - mismatched type for useQuery and UseQueryReturnType #4538

@shadskii

Description

@shadskii

Describe the bug

@tanstack/vue-query exports the type UseQueryReturnType and the function useQuery. The problem is that useQuery does not return UseQueryReturnType but instead a modified version of it. This modified version is not exported by the package. This is causing type errors for some of the hooks we've defined that wrap useQuery.

import {useQuery,UseQueryReturnType} from '@tanstack/vue-query';

const myQuery = useQuery(['key'], async () => 0);

function checkMyQuery<T>(query: UseQueryReturnType<T,unknown>){}

// this produces a type error because useQuery returns a modified version of UseQueryReturnType 
// and that type is NOT exported. 
checkMyQuery(myQuery);

Your minimal, reproducible example

https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAbwK4GcCmBFJaoE8A0AquljrgEpoxJQB2AKrmGvqXgPIBG6UAbjpRRIANjAC+cAGZQIIOAHIAAjACGtFKoDGAawD0vbAFoAjtjzyA3ACgrmiOvghcbXHAC8cVJjO4AFAG15bTRceQBdfDgVFFxaTThfAEp3AD44AAZE6ytJJDiYYHs4TQALNB0AWWcfAB56FN9TMgAuOGJvMkpqOkZmOvw87VoIAHdaFMSEMRtdXTgYMqg0OBQSiBEAEzhh+E5llXmmZZwZKDhF5atZuE4keAWcZeAUG-KVL08SHzgl7vUouAgCAbYCSYBoLb8KAoQq0OAQSRtL6dKg0BhHKK0LYLFT3DHPOAAOXY9DgaAAHpBYBCAHRwWxlSrVMi+JwuLIzOYLAkEh5RTTUFTCH6ouhwXhC7DwxFeFxXOZgETCCFSGRyWU+GkbGkwFBWGAY+hlShC9ouLpo3poOoAEVxKki9AAolBTmkPOwQMAYDUzT4LT0jrb7Y6XW7IvIlpIqKV5HAAD4KJZA-jyNIAMkQVjgOZF0ZgpVaLi4PChghEPvodtUodd0BSgSjMZK4WsuZFKbQRZ8JZwZbQQlEwZrcGddagDcjaE7rasYmyuXysOKjO0VRcADFoCbhHUGk08K0jWgd36UX8rf1BsMxhMpjZSuU18y8FuoDvWS-cFkgA

Steps to reproduce

  1. Go to reproduction link
  2. see the type error

Expected behavior

As a user I expect useQuery to return UseQueryReturnType

How often does this bug happen?

No response

Screenshots or Videos

No response

Platform

  • macOS
  • n/a
  • n/a

react-query version

4.17.0

TypeScript version

4.8.4

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