Thrown when a query is read as one data type but holds another — or when
an erased default (QueryDefaults.queryFn, structuralSharing,
MutationDefaults.mutationFn) hands back a value of the wrong type.
Each key holds exactly one data type. Reading or writing it as another
type is always a bug in the calling code, so it fails loudly here rather
than returning a silent null or a wrongly typed value (TanStack Query
casts without checking). It is thrown
synchronously, from the call that reads or writes the key —
getQueryData, setQueryData, getQueriesData, updateQueriesData,
QueryClient.query and an observer's setOptions all throw before any
future exists; only the erased-default case surfaces through the fetch or
mutation the default ran in, as its error. queryKey is null when the
default that produced the value has no key to name: a sharing hook sees
only the data, and a mutation function only its variables.
A common cause is an inferred type argument: setQueryData or
getQueryData called without <T> on a query whose type is nullable or
wider than the value. The message then says which type argument to name.
- Implemented types
Constructors
- QueryDataTypeError(QueryKey? queryKey, Type expected, Type actual)
-
Creates the error for a use of
queryKey— a read or a write — thatexpectedone type and foundactual.const
Properties
- actual → Type
-
The data type the query (or the default's value) actually holds.
final
- expected → Type
-
The data type the caller asked for — read as, or written with.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- queryKey → QueryKey?
-
The key that was read or written, or
nullwhen the mismatch came from a keyless default such as astructuralSharinghook.final - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited