Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vue-query] getQueryData/setQueryData fail to infer query data type from queryOptions.queryFn #6566

Closed
romansp opened this issue Dec 20, 2023 · 5 comments

Comments

@romansp
Copy link

romansp commented Dec 20, 2023

Describe the bug

When using queryOptions both queryClient.getQueryData and queryClient.setQueryData fail to infer query data type and fallback to unknown.

Your minimal, reproducible example

https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAbzgVwM4FMCKz1QJ4DCANsOgHYwA0cAjjvgPJgzARmpwC+cAZlBCDgAiAAIwAhuwkBjANYB6AG44AtHVx4hAbgBQO6W1TwIzVuzgBeOAAoAlJYB8teniYtD1hDrjONAaXQ8AC44AG0hAAt0IiIIIQBdOHEOAylKb198ADEyELtHRAyfKHQYZCgyOAAFfhBgDAA6EtQIIkV0awByKJiITttdH050zgG9VKNMwhJyeCs0LBdiUgo7XQn4ABNxCUsp5dmGgHNS7A0AER3xaxN3djsG9XwAvDGfd7h5eQA9AH49J7TFYwBoYGBnfCXCQ3UweWyPFwvajWMAlRSsND2CxOLzFUrlSqo9DoiBoQYfClfP46UZaIA

Steps to reproduce

  1. Go to TS playground repro.
  2. Inspect return types of getQueryData and updater callback in setQueryData

Expected behavior

Query data type should be inferred properly from queryOptions.queryFn.

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

  • vue v3.3.11

Tanstack Query adapter

vue-query

TanStack Query version

v5.14.4

TypeScript version

v5.3.3

Additional context

Types are inferred properly in @tanstack/react-query: TS playground.

I thought it's quite bizzare it doesn't work properly in vue-query knowing that it's covered by tests here.

it('should return the proper type when passed to getQueryData', () => {
doNotExecute(() => {
const { queryKey } = queryOptions({
queryKey: ['key'],
queryFn: () => Promise.resolve(5),
})
const queryClient = new QueryClient()
const data = queryClient.getQueryData(queryKey)
const result: Expect<Equal<typeof data, number | undefined>> = true
return result
})
})

But these tests are using QueryClient from @tanstack/query-core. After changing it to vue-specific QueryClient type tests start to fail. I'm not sure if that's an oversight or done on purpose.

@DamianOsipiuk
Copy link
Contributor

@roblabat Could you take a look at this?

@roblabat
Copy link
Contributor

@DamianOsipiuk I'm looking at it, it comes from queryOptions that fail to infer queryKey type correctly. I'll make a PR as soon as I'll find a solution on this.

@TkDodo
Copy link
Collaborator

TkDodo commented Jan 15, 2024

FYI we have a related PR open:

@roblabat
Copy link
Contributor

I pushed a fix @TkDodo there shouldn't be conflict with #6699

@romansp
Copy link
Author

romansp commented Jan 18, 2024

Just upgraded to 5.17.15 and types are correctly inferred now. Thanks!

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

No branches or pull requests

4 participants