TanStack / query

🤖 Powerful asynchronous state management, server-state utilities and data fetching for the web. TS/JS, React Query, Solid Query, Svelte Query and Vue Query.
https://tanstack.com/query
MIT License
40.54k stars 2.73k forks source link

[vue-query]: invalid inferred type for computed queryKey `readonly unknown[]` in queryOptions #7420

Open MellKam opened 1 month ago

MellKam commented 1 month ago

Describe the bug

import { queryOptions } from "@tanstack/vue-query"
import { computed } from "vue"

queryOptions({
    queryKey: ["hello"],
    queryFn: ({ queryKey }) => {
        queryKey
        // ^? (parameter) queryKey: string[]
    }
})

queryOptions({
    queryKey: computed(() => ["hello"]),
    queryFn: ({ queryKey }) => {
        queryKey
        // ^? (parameter) queryKey: readonly unknown[]
        // the type should be the same as in the first example without computed
    }
})

I noticed this after upgrading to the latest version of vue-query (5.35.5) from 5.29.0

Your minimal, reproducible example

typescript playground reproduction

Tanstack Query adapter

vue-query

TanStack Query version

5.35.5

TypeScript version

5.4.5

romansp commented 1 month ago

Looks like changes in this PR https://github.com/TanStack/query/pull/7390 have affected this.

Also possibly related useQuery now fails to type check MaybeRef options.

Repro: https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAbzgYwuArjApgEwDRwwCeYWcAsgIZEBGWASlgGYDyUA4ljNlATBADVKAG3RkAvnCZQ0cAOQA3MXIBQoSLERwAjmKhEWYGMAgA7AM4F05rAEU9ROJOmy5AARiULn5AGsA9EpYALS6WPqqKqjecJTIqOimMOYAXHDmMFDApgDmANoAunAAvHCFANwqWAAeGvBMicjGZrHxEInJ9uFEABTQOQCSOGkZWbkAlIgqcHBQXOhQpjoOhs0WPQjTM8vdANJYRGl5-UMEAERxCUnmZwV4WzNh+gBipmk9k8UAfHAACjIgYA2AB0c3MEGECiwPUu7Wu43uM3E40q4hUVVq0HqjTWcGsWDYOS8wAAXpQ1gBBNodcx9KCDYYUah0RisDhcHgAHlG2RyX0mmxm0QycAgRhMFhKKDQYEwuB6HxKP1hNK6+h6-CEomhJxw431lSFZhFT0cpXxat6YrW5hRWzmMAWS1NqKAA