Skip to content

Commit 43d4ed9

Browse files
committed
feat(core): convert MetaQuery and GraphQLQueryOptions to interfaces
Both types were plain type aliases, which prevented consumers from using TypeScript's declaration merging to extend MetaQuery with app-specific fields (e.g. meta.queryParams read by custom data providers). Converting them to interfaces is structurally identical and fully backward compatible, but unlocks: declare module "@refinedev/core" { interface MetaQuery { queryParams?: { _pull?: string }; } } Fixes #7527
1 parent 779d52a commit 43d4ed9

3 files changed

Lines changed: 41 additions & 10 deletions

File tree

.changeset/tame-lions-smile.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
"@refinedev/core": minor
3+
---
4+
5+
Converted `MetaQuery` and `GraphQLQueryOptions` from type aliases to interfaces.
6+
7+
This is structurally identical and fully backward compatible, but it unlocks TypeScript's [declaration merging](https://www.typescriptlang.org/docs/handbook/declaration-merging.html) for `MetaQuery`. Consumers can now extend it in their own apps to get autocompletion and type-checking for custom `meta` fields (e.g. `meta.queryParams` used by custom data providers) across every hook that accepts `meta`:
8+
9+
```ts
10+
declare module "@refinedev/core" {
11+
interface MetaQuery {
12+
queryParams?: {
13+
_pull?: string;
14+
[key: string]: unknown;
15+
};
16+
}
17+
}
18+
```
19+
20+
Previously this was not possible because declaration merging only applies to interfaces, not type aliases.

documentation/docs/core/interface-references/index.md

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,25 +203,37 @@ type OpenNotificationParams = {
203203
### MetaQuery
204204

205205
```tsx
206-
type MetaQuery = {
206+
interface MetaQuery extends QueryBuilderOptions, GraphQLQueryOptions {
207207
queryContext?: Omit<QueryFunctionContext, "meta">;
208208
[key: string]: any;
209-
} & QueryBuilderOptions &
210-
GraphQLQueryOptions;
209+
}
210+
```
211+
212+
Since `MetaQuery` is an interface, you can use [declaration merging](https://www.typescriptlang.org/docs/handbook/declaration-merging.html) to add typed fields to it (e.g. the `queryParams` your data provider reads) and get autocompletion/type-checking across every hook that accepts `meta`:
213+
214+
```tsx
215+
declare module "@refinedev/core" {
216+
interface MetaQuery {
217+
queryParams?: {
218+
_pull?: string;
219+
[key: string]: unknown;
220+
};
221+
}
222+
}
211223
```
212224

213225
### GraphQLQueryOptions
214226

215227
```tsx
216228
import type { DocumentNode } from "graphql";
217229

218-
type GraphQLQueryOptions = {
230+
interface GraphQLQueryOptions {
219231
gqlQuery?: DocumentNode;
220232
gqlMutation?: DocumentNode;
221233
gqlVariables?: {
222234
[key: string]: any;
223235
};
224-
};
236+
}
225237
```
226238

227239
### QueryFunctionContext

packages/core/src/contexts/data/types.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export interface QueryBuilderOptions {
3939
variables?: VariableOptions;
4040
}
4141

42-
export type GraphQLQueryOptions = {
42+
export interface GraphQLQueryOptions {
4343
/**
4444
* @description GraphQL query to be used by data providers.
4545
* @optional
@@ -161,13 +161,12 @@ export type GraphQLQueryOptions = {
161161
gqlVariables?: {
162162
[key: string]: any;
163163
};
164-
};
164+
}
165165

166-
export type MetaQuery = {
166+
export interface MetaQuery extends QueryBuilderOptions, GraphQLQueryOptions {
167167
[k: string]: any;
168168
queryContext?: Omit<QueryFunctionContext, "meta">;
169-
} & QueryBuilderOptions &
170-
GraphQLQueryOptions;
169+
}
171170

172171
export interface Pagination {
173172
/**

0 commit comments

Comments
 (0)