Skip to content

Commit

Permalink
feat: typed meta option for queries and mutations
Browse files Browse the repository at this point in the history
adds queryMeta and mutationMeta to the `Register` interface
  • Loading branch information
TkDodo committed Feb 28, 2023
1 parent b2f143b commit c2215d8
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/query-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import type { MutationCache } from './mutationCache'

export interface Register {
// defaultError: Error
// queryMeta: Record<string, unknown>
// mutationMeta: Record<string, unknown>
}

export type RegisteredError = Register extends {
Expand Down Expand Up @@ -72,9 +74,11 @@ export interface InfiniteData<TData> {
pageParams: unknown[]
}

export interface QueryMeta {
[index: string]: unknown
export type QueryMeta = Register extends {
queryMeta: infer TQueryMeta
}
? TQueryMeta
: Record<string, unknown>

export type NetworkMode = 'online' | 'always' | 'offlineFirst'

Expand Down Expand Up @@ -583,9 +587,11 @@ export type MutationKey = readonly unknown[]

export type MutationStatus = 'idle' | 'pending' | 'success' | 'error'

export interface MutationMeta {
[index: string]: unknown
export type MutationMeta = Register extends {
mutationMeta: infer TMutationMeta
}
? TMutationMeta
: Record<string, unknown>

export type MutationFunction<TData = unknown, TVariables = unknown> = (
variables: TVariables,
Expand Down

0 comments on commit c2215d8

Please sign in to comment.