Skip to content

Commit 12d8720

Browse files
committed
simplify typing using ApiModules instead of Omit<Api, keyof BaseApiMethods>
1 parent 36187be commit 12d8720

File tree

4 files changed

+12
-22
lines changed

4 files changed

+12
-22
lines changed

packages/toolkit/src/query/core/buildInitiate.ts

+3-6
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import type {
1414
} from '@reduxjs/toolkit'
1515
import type { SubscriptionOptions, RootState } from './apiState'
1616
import type { InternalSerializeQueryArgs } from '../defaultSerializeQueryArgs'
17-
import type { Api, ApiContext, BaseApiMethods } from '../apiTypes'
18-
import type { ApiEndpointQuery } from './module'
17+
import type { ApiContext, ApiModules } from '../apiTypes'
18+
import type { ApiEndpointQuery, CoreModule } from './module'
1919
import type { BaseQueryError, QueryReturnValue } from '../baseQueryTypes'
2020
import type { QueryResultSelectorResult } from './buildSelectors'
2121
import type { Dispatch } from 'redux'
@@ -197,10 +197,7 @@ export function buildInitiate({
197197
serializeQueryArgs: InternalSerializeQueryArgs
198198
queryThunk: QueryThunk
199199
mutationThunk: MutationThunk
200-
api: Omit<
201-
Api<any, EndpointDefinitions, any, any>,
202-
keyof BaseApiMethods<any, any, any, any>
203-
>
200+
api: ApiModules<any, EndpointDefinitions, any, any>[CoreModule]
204201
context: ApiContext<EndpointDefinitions>
205202
}) {
206203
const runningQueries: Map<

packages/toolkit/src/query/core/buildMiddleware/types.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type {
77
UnknownAction,
88
} from '@reduxjs/toolkit'
99

10-
import type { Api, ApiContext, BaseApiMethods } from '../../apiTypes'
10+
import type { ApiContext, ApiModules } from '../../apiTypes'
1111
import type {
1212
AssertTagTypes,
1313
EndpointDefinitions,
@@ -24,6 +24,7 @@ import type {
2424
QueryThunkArg,
2525
ThunkResult,
2626
} from '../buildThunks'
27+
import type { CoreModule } from '../module'
2728

2829
export type QueryStateMeta<T> = Record<string, undefined | T>
2930
export type TimeoutId = ReturnType<typeof setTimeout>
@@ -41,10 +42,7 @@ export interface BuildMiddlewareInput<
4142
context: ApiContext<Definitions>
4243
queryThunk: QueryThunk
4344
mutationThunk: MutationThunk
44-
api: Omit<
45-
Api<any, Definitions, ReducerPath, TagTypes>,
46-
keyof BaseApiMethods<any, any, any, any>
47-
>
45+
api: ApiModules<any, EndpointDefinitions, ReducerPath, TagTypes>[CoreModule]
4846
assertTagType: AssertTagTypes
4947
}
5048

packages/toolkit/src/query/react/ApiProvider.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import { useEffect } from 'react'
44
import React from 'react'
55
import type { ReactReduxContextValue } from 'react-redux'
66
import { Provider } from 'react-redux'
7+
import type { ApiModules } from '@reduxjs/toolkit/query'
78
import { setupListeners } from '@reduxjs/toolkit/query'
8-
import type { Api, BaseApiMethods } from '@reduxjs/toolkit/dist/query/apiTypes'
9+
import type { CoreModule } from '../core/module'
910

1011
/**
1112
* Can be used as a `Provider` if you **do not already have a Redux store**.
@@ -33,7 +34,7 @@ import type { Api, BaseApiMethods } from '@reduxjs/toolkit/dist/query/apiTypes'
3334
*/
3435
export function ApiProvider(props: {
3536
children: any
36-
api: Omit<Api<any, {}, any, any>, keyof BaseApiMethods<any, {}, any, any>>
37+
api: ApiModules<any, any, string, any>[CoreModule]
3738
setupListeners?: Parameters<typeof setupListeners>[1] | false
3839
context?: Context<ReactReduxContextValue>
3940
}) {

packages/toolkit/src/query/react/buildHooks.ts

+3-9
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
useRef,
1616
useState,
1717
} from 'react'
18+
import type { ApiModules } from '@reduxjs/toolkit/query'
1819
import { QueryStatus, skipToken } from '@reduxjs/toolkit/query'
1920
import type {
2021
QuerySubState,
@@ -40,11 +41,7 @@ import type {
4041
} from '@reduxjs/toolkit/dist/query/core/buildInitiate'
4142
import type { SerializeQueryArgs } from '@reduxjs/toolkit/dist/query/defaultSerializeQueryArgs'
4243
import { shallowEqual } from 'react-redux'
43-
import type {
44-
Api,
45-
ApiContext,
46-
BaseApiMethods,
47-
} from '@reduxjs/toolkit/dist/query/apiTypes'
44+
import type { ApiContext } from '@reduxjs/toolkit/dist/query/apiTypes'
4845
import type {
4946
Id,
5047
NoInfer,
@@ -595,10 +592,7 @@ export function buildHooks<Definitions extends EndpointDefinitions>({
595592
serializeQueryArgs,
596593
context,
597594
}: {
598-
api: Omit<
599-
Api<any, Definitions, any, any, CoreModule>,
600-
keyof BaseApiMethods<any, any, any, any>
601-
>
595+
api: ApiModules<any, Definitions, any, any>[CoreModule]
602596
moduleOptions: Required<ReactHooksModuleOptions>
603597
serializeQueryArgs: SerializeQueryArgs<any>
604598
context: ApiContext<Definitions>

0 commit comments

Comments
 (0)