From c2215d87797335fd1aa3176eec93f28899e55d9c Mon Sep 17 00:00:00 2001 From: Dominik Dorfmeister Date: Tue, 28 Feb 2023 11:15:44 +0100 Subject: [PATCH] feat: typed meta option for queries and mutations adds queryMeta and mutationMeta to the `Register` interface --- packages/query-core/src/types.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/query-core/src/types.ts b/packages/query-core/src/types.ts index a82ea0c6be..bdad93a612 100644 --- a/packages/query-core/src/types.ts +++ b/packages/query-core/src/types.ts @@ -9,6 +9,8 @@ import type { MutationCache } from './mutationCache' export interface Register { // defaultError: Error + // queryMeta: Record + // mutationMeta: Record } export type RegisteredError = Register extends { @@ -72,9 +74,11 @@ export interface InfiniteData { pageParams: unknown[] } -export interface QueryMeta { - [index: string]: unknown +export type QueryMeta = Register extends { + queryMeta: infer TQueryMeta } + ? TQueryMeta + : Record export type NetworkMode = 'online' | 'always' | 'offlineFirst' @@ -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 export type MutationFunction = ( variables: TVariables,