You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Typescript infers type of context as unknown if onMutate comes after onSuccess, onError or onSettled, in the following codeblock mutation1 typescript reports the type of context to be unknown which is wrong, in mutation2 typescript reports type of context to be { foo: string } | undefined which is expected and correct
Goto src/routes/index.tsx and hover over the context errors
Expected behavior
The order of keys don't matter and type of context is correctly inferred, I understand the workaround is pretty simple but I use a prettier plugin that orders all object keys alphabetically which is good for stable git diffs
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
OS: Linux vc-arch 6.12.10-zen1-1-zen #1 ZEN SMP PREEMPT_DYNAMIC Sat, 18 Jan 2025 02:26:52 +0000 x86_64 GNU/Linux
Browser: N/A
Editor: Neovim
Tanstack Query adapter
solid-query
TanStack Query version
5.66.0
TypeScript version
5.7.3
Additional context
It only happens if the argument list of onMutate is non empty
The text was updated successfully, but these errors were encountered:
please, for typescript related issues, typescript playground is so much better.
anyways, the issue is that the producer (onMutate) must come before the consumer (onError, onSuccess). This is a known TS limitation around intra expression inference:
Describe the bug
Typescript infers type of context as unknown if
onMutate
comes afteronSuccess
,onError
oronSettled
, in the following codeblockmutation1
typescript reports the type of context to beunknown
which is wrong, inmutation2
typescript reports type of context to be{ foo: string } | undefined
which is expected and correctYour minimal, reproducible example
https://stackblitz.com/edit/github-iy58hbhh?file=src%2Froutes%2Findex.tsx
Steps to reproduce
Expected behavior
The order of keys don't matter and type of context is correctly inferred, I understand the workaround is pretty simple but I use a prettier plugin that orders all object keys alphabetically which is good for stable git diffs
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
OS: Linux vc-arch 6.12.10-zen1-1-zen #1 ZEN SMP PREEMPT_DYNAMIC Sat, 18 Jan 2025 02:26:52 +0000 x86_64 GNU/Linux
Browser: N/A
Editor: Neovim
Tanstack Query adapter
solid-query
TanStack Query version
5.66.0
TypeScript version
5.7.3
Additional context
It only happens if the argument list of
onMutate
is non emptyThe text was updated successfully, but these errors were encountered: