From b7a64c4355fff29e40eb4f9d91aa9c447c897e4c Mon Sep 17 00:00:00 2001 From: Stefan Vojvodic Date: Mon, 15 May 2023 17:20:21 +0200 Subject: [PATCH 1/2] refactor(query-core): change QueryMeta and MutationMeta to accept generic types --- packages/query-core/src/types.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/packages/query-core/src/types.ts b/packages/query-core/src/types.ts index 9426089293b..f81eeb880fb 100644 --- a/packages/query-core/src/types.ts +++ b/packages/query-core/src/types.ts @@ -48,7 +48,12 @@ export interface InfiniteData { pageParams: unknown[] } -export interface QueryMeta { +export interface QueryMeta< + TQueryFnData = unknown, + TError = unknown, + TData = TQueryFnData, + TQueryKey extends QueryKey = QueryKey, +> { [index: string]: unknown } @@ -101,7 +106,7 @@ export interface QueryOptions< * Additional payload to be stored on each query. * Use this property to pass information that can be used in other places. */ - meta?: QueryMeta + meta?: QueryMeta } export type UseErrorBoundary< @@ -544,7 +549,12 @@ export type MutationKey = readonly unknown[] export type MutationStatus = 'idle' | 'loading' | 'success' | 'error' -export interface MutationMeta { +export interface MutationMeta< + TData = unknown, + TError = unknown, + TVariables = void, + TContext = unknown, +> { [index: string]: unknown } @@ -585,7 +595,7 @@ export interface MutationOptions< networkMode?: NetworkMode cacheTime?: number _defaulted?: boolean - meta?: MutationMeta + meta?: MutationMeta } export interface MutationObserverOptions< From 9dbd96414c3dc639c02d2452cdd48e0649289ac6 Mon Sep 17 00:00:00 2001 From: Stefan Vojvodic Date: Tue, 16 May 2023 11:23:46 +0200 Subject: [PATCH 2/2] Change default type value and add ts-expect-error --- packages/query-core/src/types.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/query-core/src/types.ts b/packages/query-core/src/types.ts index f81eeb880fb..788cd66369c 100644 --- a/packages/query-core/src/types.ts +++ b/packages/query-core/src/types.ts @@ -549,10 +549,11 @@ export type MutationKey = readonly unknown[] export type MutationStatus = 'idle' | 'loading' | 'success' | 'error' +// @ts-expect-error export interface MutationMeta< TData = unknown, TError = unknown, - TVariables = void, + TVariables = unknown, TContext = unknown, > { [index: string]: unknown