Skip to main content

Query Result Types

UseQueryHookResult

Complete result type combining query state and subscription functionality.
type UseQueryHookResult<
  D extends QueryDefinition<any, any, any, any>,
  R = UseQueryStateDefaultResult<D>,
> = UseQueryStateResult<D, R> & UseQuerySubscriptionResult<D>;
Properties:
  • All state signals from UseQueryStateResult
  • refetch() method from UseQuerySubscriptionResult
Example:
export class PostComponent {
  postQuery = useGetPostQuery(this.postId);
  // Access signals
  isLoading = this.postQuery.isLoading;
  data = this.postQuery.data;
  // Call methods
  refresh() {
    this.postQuery.refetch();
  }
}

TypedUseQueryHookResult

Helper type for creating strongly-typed query results.
type TypedUseQueryHookResult<
  ResultType,
  QueryArg,
  BaseQuery extends BaseQueryFn,
  R = UseQueryStateDefaultResult<...>
> = TypedUseQueryStateResult<ResultType, QueryArg, BaseQuery, R> &
  TypedUseQuerySubscriptionResult<ResultType, QueryArg, BaseQuery>;

UseQueryStateResult

Deep signal wrapper for query state.
type UseQueryStateResult<
  _ extends QueryDefinition<any, any, any, any>,
  R
> = DeepSignal<TSHelpersNoInfer<R>>;
Provides fine-grained signal access to all state properties:
postQuery = useGetPostQuery(id);

// Access as signals (recommended for change detection)
postQuery.isLoading();
postQuery.data();
postQuery.error();
postQuery.currentData();

// Access as object (evaluates all signals)
const state = postQuery();
state.isLoading; // boolean
state.data; // Post | undefined

UseQueryStateDefaultResult

Default state shape returned by query hooks.
type UseQueryStateDefaultResult<D extends QueryDefinition<any, any, any, any>> = 
  | UseQueryStateUninitialized<D>
  | UseQueryStateLoading<D>
  | UseQueryStateSuccessFetching<D>
  | UseQueryStateSuccessNotFetching<D>
  | UseQueryStateError<D>;
status
QueryStatus
Current query status: 'uninitialized' | 'pending' | 'fulfilled' | 'rejected'
Deprecated. Use boolean flags instead: isLoading, isFetching, isSuccess, isError, isUninitialized
data
ResultType | undefined
The result data from the query. Holds previous data while refetching.
currentData
ResultType | undefined
The result data for the current query arguments. Unlike data, this is cleared when arguments change.
error
unknown
Error object if the query failed.
isUninitialized
boolean
true when the query has not started yet.
isLoading
boolean
true when the query is loading for the first time (no data yet).
isFetching
boolean
true when the query is currently fetching, but might have data from an earlier request.
isSuccess
boolean
true when the query has data from a successful load.
isError
boolean
true when the query is in an error state.
fulfilledTimeStamp
number | undefined
Timestamp when the query was successfully fulfilled.
Example:
postQuery = useGetPostQuery(id);

// In template
@if (postQuery.isLoading()) {
  <p>Loading...</p>
}
@if (postQuery.isError()) {
  <p>Error: {{ postQuery.error() }}</p>
}
@if (postQuery.data(); as post) {
  <h1>{{ post.title }}</h1>
}

UseQuerySubscriptionResult

Result from subscription-only query hooks.
type UseQuerySubscriptionResult<D extends QueryDefinition<any, any, any, any>> = Pick<
  QueryActionCreatorResult<D>,
  'refetch'
>;
refetch
() => QueryActionCreatorResult<D>
Triggers a refetch of the query data. Returns a promise-like object with .unwrap().
Example:
useQuerySubscription(id);
const { refetch } = useQuerySubscription(id);

refreshData() {
  refetch().unwrap()
    .then(data => console.log('Refreshed:', data))
    .catch(error => console.error('Refresh failed:', error));
}

UseLazyQueryStateResult

State result from lazy query hooks.
type UseLazyQueryStateResult<
  D extends QueryDefinition<any, any, any, any>,
  R = UseQueryStateDefaultResult<D>,
> = SignalsMap<TSHelpersNoInfer<R>> & {
  reset: () => void;
};
reset
() => void
Resets the hook state to its initial uninitialized state and removes the last result from the cache.
Example:
searchQuery = useLazyGetPostsQuery();

clearSearch() {
  this.searchQuery.reset();
  // State is now uninitialized, data cleared
}

UseLazyQueryLastPromiseInfo

Tracking info for lazy query arguments.
type UseLazyQueryLastPromiseInfo<D extends QueryDefinition<any, any, any, any>> = {
  lastArg: Signal<QueryArgFrom<D>>;
};
lastArg
Signal<QueryArgFrom<D>>
Signal containing the last argument used to trigger the lazy query.

Infinite Query Result Types

UseInfiniteQueryHookResult

Complete result for infinite query hooks.
type UseInfiniteQueryHookResult<
  D extends InfiniteQueryDefinition<any, any, any, any, any>,
  R = UseInfiniteQueryStateDefaultResult<D>,
> = UseInfiniteQueryStateResult<D, R> & 
  Pick<UseInfiniteQuerySubscriptionResult<D>, 'refetch' | 'fetchNextPage' | 'fetchPreviousPage'>;
Properties:
  • All state signals from UseInfiniteQueryStateResult
  • Pagination methods: fetchNextPage(), fetchPreviousPage(), refetch()

UseInfiniteQueryStateDefaultResult

Default state for infinite queries, similar to regular queries but with pagination info.
type UseInfiniteQueryStateDefaultResult<
  D extends InfiniteQueryDefinition<any, any, any, any, any>
> = (
  | UseInfiniteQueryStateUninitialized<D>
  | UseInfiniteQueryStateLoading<D>
  | UseInfiniteQueryStateSuccessFetching<D>
  | UseInfiniteQueryStateSuccessNotFetching<D>
  | UseInfiniteQueryStateError<D>
) & { status: QueryStatus };
data
InfiniteData<ResultType, PageParam> | undefined
Structure containing all fetched pages:
{
  pages: Data[],      // Array of page results
  pageParams: Param[] // Array of page parameters used
}
hasNextPage
boolean
true if there are more pages available to fetch forward.
hasPreviousPage
boolean
true if there are more pages available to fetch backward.
isFetchingNextPage
boolean
true when fetching the next page.
isFetchingPreviousPage
boolean
true when fetching the previous page.
Example:
postsQuery = useGetPostsInfiniteQuery(undefined, {
  initialPageParam: 0,
});

loadMore() {
  if (this.postsQuery.hasNextPage() && !this.postsQuery.isFetchingNextPage()) {
    this.postsQuery.fetchNextPage();
  }
}

// In template
@for (page of postsQuery.data()?.pages ?? []; track $index) {
  @for (post of page; track post.id) {
    <div>{{ post.title }}</div>
  }
}
@if (postsQuery.hasNextPage()) {
  <button (click)="loadMore()" [disabled]="postsQuery.isFetchingNextPage()">
    Load More
  </button>
}

UseInfiniteQuerySubscriptionResult

Subscription result for infinite queries with pagination controls.
type UseInfiniteQuerySubscriptionResult<
  D extends InfiniteQueryDefinition<any, any, any, any, any>
> = {
  refetch: (options?: Pick<UseInfiniteQuerySubscriptionOptions<D>, 'refetchCachedPages'>) => InfiniteQueryActionCreatorResult<D>;
  trigger: LazyInfiniteQueryTrigger<D>;
  fetchNextPage: () => InfiniteQueryActionCreatorResult<D>;
  fetchPreviousPage: () => InfiniteQueryActionCreatorResult<D>;
};
fetchNextPage
() => Promise
Fetches the next page using the getNextPageParam callback defined in the endpoint.
fetchPreviousPage
() => Promise
Fetches the previous page using the getPreviousPageParam callback defined in the endpoint.
refetch
(options?) => Promise
Refetches all cached pages. Pass { refetchCachedPages: false } to only refetch the first page.

Mutation Result Types

UseMutationStateResult

State result from mutation hooks.
type UseMutationStateResult<
  D extends MutationDefinition<any, any, any, any>,
  R
> = SignalsMap<TSHelpersNoInfer<R>> & {
  originalArgs: Signal<QueryArgFrom<D> | undefined>;
  reset: () => void;
};
data
ResultType | undefined
The result data from the mutation.
error
unknown
Error object if the mutation failed.
isUninitialized
boolean
true when the mutation has not been triggered yet.
isLoading
boolean
true when the mutation is currently in progress.
isSuccess
boolean
true when the mutation completed successfully.
isError
boolean
true when the mutation failed.
originalArgs
Signal<QueryArgFrom<D> | undefined>
Signal containing the original arguments used to trigger the mutation.
reset
() => void
Resets the mutation state to its initial uninitialized state and removes the last result from the cache.
Example:
addPost = useAddPostMutation();

// In template
<button 
  (click)="addPost({ title: 'New Post' })" 
  [disabled]="addPost.isLoading()">
  {{ addPost.isLoading() ? 'Saving...' : 'Add Post' }}
</button>

@if (addPost.isError()) {
  <p>Error: {{ addPost.error() }}</p>
  <button (click)="addPost.reset()">Dismiss</button>
}

@if (addPost.isSuccess()) {
  <p>Post created: {{ addPost.data()?.title }}</p>
}

TypedUseMutationResult

Helper type for creating strongly-typed mutation results.
type TypedUseMutationResult<
  ResultType,
  QueryArg,
  BaseQuery extends BaseQueryFn,
  R = MutationResultSelectorResult<MutationDefinition<QueryArg, BaseQuery, string, ResultType, string>>,
> = UseMutationStateResult<MutationDefinition<QueryArg, BaseQuery, string, ResultType, string>, R>;

Utility Types

DeepSignal

Recursively wraps an object structure with signals for fine-grained reactivity.
type DeepSignal<T> = {
  (): T;
  [K in keyof T]: Signal<T[K]>;
};
Allows accessing properties as individual signals or as a computed object:
query = useGetPostQuery(id);

// As individual signals
query.isLoading(); // Signal<boolean>
query.data();      // Signal<Post | undefined>

// As computed object
query(); // { isLoading: boolean, data: Post | undefined, ... }

SignalsMap

Maps object properties to signals.
type SignalsMap<T> = {
  [K in keyof T]: Signal<T[K]>;
};
Used for mutation and lazy query results where the root is not callable:
addPost = useAddPostMutation();
// addPost is not callable
addPost.isLoading(); // But properties are signals

Build docs developers (and LLMs) love