Skip to content

setQueryData updater function's parameter incorrectly typed as unknown in expression body arrow functions #9024

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

Closed
custardcream98 opened this issue Apr 15, 2025 · 0 comments · Fixed by #9030 · May be fixed by coderabbit-test/query#1
Labels

Comments

@custardcream98
Copy link
Contributor

custardcream98 commented Apr 15, 2025

Describe the bug

When using queryClient.setQueryData inside an expression body arrow function (without curly braces), the updater function's data parameter is incorrectly typed as unknown.

However, when used in a block body arrow function (with curly braces), the type is correctly inferred as expected.

Your minimal, reproducible example

https://stackblitz.com/edit/tanstack-query-wcdibka8?file=src%2Findex.tsx

Steps to reproduce

  1. Visit the StackBlitz reproduction
  2. Check the type inference on both mutation1 and mutation2 examples
  3. Observe that in mutation1 (expression body), the data parameter is typed as unknown
  4. Observe that in mutation2 (block body), the data parameter is correctly typed as { data: string } | undefined

Expected behavior

The updater function's data parameter should be correctly typed in both cases, regardless of whether the arrow function uses an expression body or block body syntax.

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

  • MacOS
  • I don't think this issue is related to what platform I use.

Tanstack Query adapter

None

TanStack Query version

v5.74.3

TypeScript version

v5.8.3

Additional context

I am looking into it and once I find a solution, I'll submit a PR.

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