Describe the bug
useMutationState does not preserve type information inside the select callback. The mutation parameter is typed as a non-generic Mutation, causing mutation.state.data to be inferred as unknown.
Reproduction
const result = useMutationState({
select: (mutation) => mutation.state.data
})
Your minimal, reproducible example
import type { Mutation } from '@tanstack/query-core' type MutationStateOptions<TResult = unknown> = { select?: (mutation: Mutation) => TResult } function test() { const options: MutationStateOptions = { select: (mutation) => { return mutation.state.data }, } const result = options.select?.({} as any) // ❌ inferred as unknown return result }
Steps to reproduce
- Use useMutationState with a select callback
- Access mutation.state.data inside select
- Observe the inferred type of the result
Expected behavior
The type of mutation.state.data should be correctly inferred based on the mutation's generic type (e.g., number, string, etc.), and the returned result should reflect that type (e.g., number[]).
How often does this bug happen?
None
Screenshots or Videos
No response
Platform
For all
Tanstack Query adapter
None
TanStack Query version
@tanstack/react-query v5 (latest)
TypeScript version
No response
Additional context
The type of mutation.state.data is inferred as unknown because Mutation is used without generics. As a result, the final returned value from useMutationState is typed as unknown[].
Describe the bug
useMutationStatedoes not preserve type information inside theselectcallback. Themutationparameter is typed as a non-genericMutation, causingmutation.state.datato be inferred asunknown.Reproduction
Your minimal, reproducible example
Steps to reproduce
Expected behavior
The type of mutation.state.data should be correctly inferred based on the mutation's generic type (e.g., number, string, etc.), and the returned result should reflect that type (e.g., number[]).
How often does this bug happen?
None
Screenshots or Videos
No response
Platform
For all
Tanstack Query adapter
None
TanStack Query version
@tanstack/react-query v5 (latest)
TypeScript version
No response
Additional context
The type of mutation.state.data is inferred as unknown because Mutation is used without generics. As a result, the final returned value from useMutationState is typed as unknown[].