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

BaseQueryNarrowing.md

33 lines1.8 KB

1---
2id: BaseQueryNarrowing
3title: BaseQueryNarrowing
4---
5​
6Defined in: [packages/angular-query-experimental/src/types.ts:80](https://github.com/TanStack/query/blob/main/packages/angular-query-experimental/src/types.ts#L80)
7​
8The `isSuccess`/`isError`/`isPending` methods on a query result. Unlike `react-query`'s derived booleans,
9these are type-guard methods you call β€” `if (query.isSuccess())` β€” so that `query.data` narrows away
10`undefined` inside the branch, the same way `status` narrowing works on the plain object `react-query`
11returns.
12​
13## Type Parameters
14​
15### TData
16​
17`TData` = `unknown`
18​
19The type `data` ends up as after `select` runs.
20​
21### TError
22​
23`TError` = [`DefaultError`](../type-aliases/DefaultError.md)
24​
25The type of errors your `queryFn` may throw.
26​
27## Properties
28​
29| Property | Type | Description |
30| ------ | ------ | ------ |
31| <a id="property-iserror"></a> `isError` | (`this`: [`CreateBaseQueryResult`](../type-aliases/CreateBaseQueryResult.md)\<`TData`, `TError`\>) => `this is CreateBaseQueryResult<TData, TError, CreateStatusBasedQueryResult<"error", TData, TError>>` | Returns `true` if the query is in the `error` state, narrowing the result to that state. |
32| <a id="property-ispending"></a> `isPending` | (`this`: [`CreateBaseQueryResult`](../type-aliases/CreateBaseQueryResult.md)\<`TData`, `TError`\>) => `this is CreateBaseQueryResult<TData, TError, CreateStatusBasedQueryResult<"pending", TData, TError>>` | Returns `true` if the query is in the `pending` state, narrowing the result to that state. |
33| <a id="property-issuccess"></a> `isSuccess` | (`this`: [`CreateBaseQueryResult`](../type-aliases/CreateBaseQueryResult.md)\<`TData`, `TError`\>) => `this is CreateBaseQueryResult<TData, TError, CreateStatusBasedQueryResult<"success", TData, TError>>` | Returns `true` if the query is in the `success` state, narrowing the result to that state. |