Skip to content
Source
Sign inSign up
TanStack/query

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

Send to my agent
Closedcustardcream98(GitHub profile, opens in a new tab) opened this issue 0 comments

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.

  1. TkDodo added labelstypes

  2. TkDodo closed this

Sign in to join this conversation.