diff --git a/src/query/react/index.ts b/src/query/react/index.ts index defc3d36bf..103854e5e0 100644 --- a/src/query/react/index.ts +++ b/src/query/react/index.ts @@ -1,26 +1,22 @@ -import { reactHooksModuleName, ReactHooksBaseEndpoints } from './module' +import { coreModule, coreModuleName } from '../core/module' +import { buildCreateApi, CreateApi } from '../createApi' +import { reactHooksModule, reactHooksModuleName } from './module' -import { EndpointDefinitions } from '../endpointDefinitions' +import { MutationHooks, QueryHooks } from './buildHooks' +import { + EndpointDefinitions, + QueryDefinition, + MutationDefinition, + QueryArgFrom, +} from '../endpointDefinitions' import { BaseQueryFn } from '../baseQueryTypes' -import { HooksWithUniqueNames } from './versionedTypes' + +import { QueryKeys } from '../core/apiState' +import { PrefetchOptions } from '../core/module' export * from '..' export { ApiProvider } from './ApiProvider' -export { createApi } from './reactHooksCommonExports' -export * from './reactHooksCommonExports' +const createApi = buildCreateApi(coreModule(), reactHooksModule()) -declare module '../apiTypes' { - export interface ApiModules< - // eslint-disable-next-line @typescript-eslint/no-unused-vars - BaseQuery extends BaseQueryFn, - Definitions extends EndpointDefinitions, - // eslint-disable-next-line @typescript-eslint/no-unused-vars - ReducerPath extends string, - // eslint-disable-next-line @typescript-eslint/no-unused-vars - TagTypes extends string - > { - [reactHooksModuleName]: ReactHooksBaseEndpoints & - HooksWithUniqueNames - } -} +export { createApi, reactHooksModule } diff --git a/src/query/react/module.ts b/src/query/react/module.ts index 81a384ac5a..11d7cd6413 100644 --- a/src/query/react/module.ts +++ b/src/query/react/module.ts @@ -12,6 +12,8 @@ import { capitalize } from '../utils' import { safeAssign } from '../tsHelpers' import { BaseQueryFn } from '../baseQueryTypes' +import { HooksWithUniqueNames } from './versionedTypes/index' + import { useDispatch as rrUseDispatch, useSelector as rrUseSelector, @@ -24,35 +26,45 @@ import { PrefetchOptions } from '../core/module' export const reactHooksModuleName = Symbol() export type ReactHooksModule = typeof reactHooksModuleName -export interface ReactHooksBaseEndpoints< - Definitions extends EndpointDefinitions -> { - /** - * Endpoints based on the input endpoints provided to `createApi`, containing `select`, `hooks` and `action matchers`. - */ - endpoints: { - [K in keyof Definitions]: Definitions[K] extends QueryDefinition< - any, - any, - any, - any, - any - > - ? QueryHooks - : Definitions[K] extends MutationDefinition - ? MutationHooks - : never +declare module '../apiTypes' { + export interface ApiModules< + // eslint-disable-next-line @typescript-eslint/no-unused-vars + BaseQuery extends BaseQueryFn, + Definitions extends EndpointDefinitions, + // eslint-disable-next-line @typescript-eslint/no-unused-vars + ReducerPath extends string, + // eslint-disable-next-line @typescript-eslint/no-unused-vars + TagTypes extends string + > { + [reactHooksModuleName]: { + /** + * Endpoints based on the input endpoints provided to `createApi`, containing `select`, `hooks` and `action matchers`. + */ + endpoints: { + [K in keyof Definitions]: Definitions[K] extends QueryDefinition< + any, + any, + any, + any, + any + > + ? QueryHooks + : Definitions[K] extends MutationDefinition + ? MutationHooks + : never + } + /** + * A hook that accepts a string endpoint name, and provides a callback that when called, pre-fetches the data for that endpoint. + */ + usePrefetch>( + endpointName: EndpointName, + options?: PrefetchOptions + ): ( + arg: QueryArgFrom, + options?: PrefetchOptions + ) => void + } & HooksWithUniqueNames } - /** - * A hook that accepts a string endpoint name, and provides a callback that when called, pre-fetches the data for that endpoint. - */ - usePrefetch>( - endpointName: EndpointName, - options?: PrefetchOptions - ): ( - arg: QueryArgFrom, - options?: PrefetchOptions - ) => void } // type RR = typeof import('react-redux') diff --git a/src/query/react/reactHooksCommonExports.ts b/src/query/react/reactHooksCommonExports.ts deleted file mode 100644 index a9942d9c51..0000000000 --- a/src/query/react/reactHooksCommonExports.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { coreModule, coreModuleName } from '../core/module' -import { buildCreateApi, CreateApi } from '../createApi' -import { - reactHooksModule, - reactHooksModuleName, - ReactHooksBaseEndpoints, -} from './module' - -import { MutationHooks, QueryHooks } from './buildHooks' -import { - EndpointDefinitions, - QueryDefinition, - MutationDefinition, - QueryArgFrom, -} from '../endpointDefinitions' -import { BaseQueryFn } from '../baseQueryTypes' - -import { QueryKeys } from '../core/apiState' -import { PrefetchOptions } from '../core/module' - -const createApi = buildCreateApi(coreModule(), reactHooksModule()) - -export { createApi, reactHooksModule }