Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add types for QueryFilters which flow down to Query<> and QueryKey/DataTag types #8332

Merged
merged 8 commits into from
Nov 27, 2024
10 changes: 8 additions & 2 deletions packages/query-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -534,11 +534,17 @@ export interface RefetchOptions extends ResultOptions {
cancelRefetch?: boolean
}

export interface InvalidateQueryFilters extends QueryFilters {
export interface InvalidateQueryFilters<TQueryFnData = unknown, TError = Error, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> extends QueryFilters<TQueryFnData,
TError,
TData,
TQueryKey> {
refetchType?: QueryTypeFilter | 'none'
}

export interface RefetchQueryFilters extends QueryFilters {}
export interface RefetchQueryFilters<TQueryFnData = unknown, TError = Error, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> extends QueryFilters<TQueryFnData,
TError,
TData,
TQueryKey> {}

export interface InvalidateOptions extends RefetchOptions {}
export interface ResetOptions extends RefetchOptions {}
Expand Down
10 changes: 7 additions & 3 deletions packages/query-core/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type {
DataTag,
DefaultError,
Enabled,
FetchStatus,
Expand All @@ -14,7 +15,7 @@ import type { FetchOptions, Query } from './query'

// TYPES

export interface QueryFilters {
export interface QueryFilters<TQueryFnData = unknown, TError = Error, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> {
/**
* Filter to active queries, inactive queries or all queries
*/
Expand All @@ -26,11 +27,14 @@ export interface QueryFilters {
/**
* Include queries matching this predicate function
*/
predicate?: (query: Query) => boolean
predicate?: (query: Query<TQueryFnData,
TError,
TData,
TQueryKey>) => boolean
/**
* Include queries matching this query key
*/
queryKey?: QueryKey
queryKey?: unknown extends TQueryFnData ? QueryKey : (QueryKey & DataTag<unknown, TQueryFnData>)
/**
* Include or exclude stale queries
*/
Expand Down
Loading