Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

BaseMutationNarrowing.md

49 lines3.7 KB

1---
2id: BaseMutationNarrowing
3title: BaseMutationNarrowing
4---
5​
6<!-- DO NOT EDIT: this page is autogenerated from the type comments -->
7​
8Defined in: [packages/angular-query/src/types.ts:454](https://github.com/TanStack/query/blob/main/packages/angular-query/src/types.ts#L454)
9​
10Signal-backed guards that narrow mutation data, errors, and variables by the current status: the
11`isSuccess`/`isError`/`isPending`/`isIdle` methods on a mutation result. Each is a `Signal` you call to
12read its current boolean value reactively, and the call is also a type guard β€” `if (mutation.isSuccess())`
13β€” so that `mutation.data` narrows away `undefined` inside the branch.
14​
15## Type Parameters
16​
17### TData
18​
19`TData` = `unknown`
20​
21The type your mutation function resolves to.
22​
23### TError
24​
25`TError` = [`DefaultError`](../type-aliases/DefaultError.md)
26​
27The type of errors your mutation function may throw.
28​
29### TVariables
30​
31`TVariables` = `unknown`
32​
33The type of the variable passed to `mutate`/`mutateAsync`.
34​
35### TOnMutateResult
36​
37`TOnMutateResult` = `unknown`
38​
39The type returned by `onMutate`, passed to `onSuccess`/`onError`/`onSettled` as
40their `onMutateResult` parameter β€” useful for optimistic-update rollback data.
41​
42## Properties
43​
44| Property | Type | Description |
45| ------ | ------ | ------ |
46| <a id="property-iserror"></a> `isError` | `SignalFunction`\<(`this`: [`CreateMutationResult`](../type-aliases/CreateMutationResult.md)\<`TData`, `TError`, `TVariables`, `TOnMutateResult`\>) => `this is CreateMutationResult<TData, TError, TVariables, TOnMutateResult, Override<MutationObserverErrorResult<TData, TError, TVariables, TOnMutateResult>, { mutate: CreateMutateFunction<TData, TError, TVariables, TOnMutateResult> }> & { mutateAsync: CreateMutateAsyncFunction<TData, TError, TVariables, TOnMutateResult> }>`\> | Whether the mutation is in the `error` state. Calling it narrows the result to that state. |
47| <a id="property-isidle"></a> `isIdle` | `SignalFunction`\<(`this`: [`CreateMutationResult`](../type-aliases/CreateMutationResult.md)\<`TData`, `TError`, `TVariables`, `TOnMutateResult`\>) => `this is CreateMutationResult<TData, TError, TVariables, TOnMutateResult, Override<MutationObserverIdleResult<TData, TError, TVariables, TOnMutateResult>, { mutate: CreateMutateFunction<TData, TError, TVariables, TOnMutateResult> }> & { mutateAsync: CreateMutateAsyncFunction<TData, TError, TVariables, TOnMutateResult> }>`\> | Whether the mutation is in the `idle` state. Calling it narrows the result to that state. |
48| <a id="property-ispending"></a> `isPending` | `SignalFunction`\<(`this`: [`CreateMutationResult`](../type-aliases/CreateMutationResult.md)\<`TData`, `TError`, `TVariables`, `TOnMutateResult`\>) => `this is CreateMutationResult<TData, TError, TVariables, TOnMutateResult, Override<MutationObserverLoadingResult<TData, TError, TVariables, TOnMutateResult>, { mutate: CreateMutateFunction<TData, TError, TVariables, TOnMutateResult> }> & { mutateAsync: CreateMutateAsyncFunction<TData, TError, TVariables, TOnMutateResult> }>`\> | Whether the mutation is in the `pending` state. Calling it narrows the result to that state. |
49| <a id="property-issuccess"></a> `isSuccess` | `SignalFunction`\<(`this`: [`CreateMutationResult`](../type-aliases/CreateMutationResult.md)\<`TData`, `TError`, `TVariables`, `TOnMutateResult`\>) => `this is CreateMutationResult<TData, TError, TVariables, TOnMutateResult, Override<MutationObserverSuccessResult<TData, TError, TVariables, TOnMutateResult>, { mutate: CreateMutateFunction<TData, TError, TVariables, TOnMutateResult> }> & { mutateAsync: CreateMutateAsyncFunction<TData, TError, TVariables, TOnMutateResult> }>`\> | Whether the mutation is in the `success` state. Calling it narrows the result to that state. |