typed<TData, TVariables, TOnMutateResult, TSelected> static method

MutationStateObserver<TSelected> typed<TData, TVariables, TOnMutateResult, TSelected>(
  1. QueryClient client, {
  2. MutationFilters filters = const MutationFilters(),
  3. required TypedMutationStateSelect<TData, TVariables, TOnMutateResult, TSelected> select,
})

A selection over the mutations of one type, select receiving them typed — no cast to get at state.variables. (TanStack Query's useMutationState has only the untyped form.)

The types usually come from select's parameter:

MutationStateObserver.typed(
  client,
  filters: const MutationFilters(status: MutationStatus.pending),
  select: (Mutation<Object?, SensorIntent, Object?> mutation) =>
      mutation.state.variables!,
);

The filter is a mutation's declared type arguments, not the runtime type of its variables: one built from options whose types were never written or inferred is a Mutation<Object?, Object?, Object?> and drops out silently.

The type test belongs to the observer, not to filters: it applies on top of whatever filters a later setOptions passes, so the selection only ever holds mutations of the declared types. A select passed to setOptions has the erased signature, and receives those mutations only — cast one to its declared type to read it typed. The type test runs first, so a predicate in filters only ever sees mutations of the declared types and may cast to them.

Implementation

static MutationStateObserver<TSelected> typed<TData, TVariables,
        TOnMutateResult, TSelected>(
  QueryClient client, {
  MutationFilters filters = const MutationFilters(),
  required TypedMutationStateSelect<TData, TVariables, TOnMutateResult,
          TSelected>
      select,
}) =>
    MutationStateObserver<TSelected>._(
      client,
      filters,
      (mutation) =>
          select(mutation as Mutation<TData, TVariables, TOnMutateResult>),
      (mutation) => mutation is Mutation<TData, TVariables, TOnMutateResult>,
    );