query icon indicating copy to clipboard operation
query copied to clipboard

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

Open MellKam opened this issue 1 year ago • 1 comments

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

MellKam avatar May 12 '24 09:05 MellKam

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

romansp avatar May 13 '24 18:05 romansp