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

BaseMutationNarrowing.md

48 lines3.6 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-experimental/src/types.ts:324](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/types.ts#L324)
9​
10The `isSuccess`/`isError`/`isPending`/`isIdle` methods on a mutation result. Each is both a `Signal`
11(its current boolean value is read reactively without calling it) and a type-guard function you can
12call β€” `if (mutation.isSuccess())` β€” so that `mutation.data` narrows away `undefined` inside the branch.
13​
14## Type Parameters
15​
16### TData
17​
18`TData` = `unknown`
19​
20The type your mutation function resolves to.
21​
22### TError
23​
24`TError` = [`DefaultError`](../type-aliases/DefaultError.md)
25​
26The type of errors your mutation function may throw.
27​
28### TVariables
29​
30`TVariables` = `unknown`
31​
32The type of the variable passed to `mutate`/`mutateAsync`.
33​
34### TOnMutateResult
35​
36`TOnMutateResult` = `unknown`
37​
38The type returned by `onMutate`, passed to `onSuccess`/`onError`/`onSettled` as
39their `onMutateResult` parameter β€” useful for optimistic-update rollback data.
40​
41## Properties
42​
43| Property | Type | Description |
44| ------ | ------ | ------ |
45| <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. |
46| <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. |
47| <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. |
48| <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. |