Skip to content

Commit

Permalink
Revert the "ApiModule" move to fix TS errors
Browse files Browse the repository at this point in the history
  • Loading branch information
markerikson committed Apr 24, 2021
1 parent 69cba87 commit d2aaff0
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 70 deletions.
34 changes: 15 additions & 19 deletions src/query/react/index.ts
Original file line number Diff line number Diff line change
@@ -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<Definitions> &
HooksWithUniqueNames<Definitions>
}
}
export { createApi, reactHooksModule }
68 changes: 40 additions & 28 deletions src/query/react/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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]>
: Definitions[K] extends MutationDefinition<any, any, any, any, any>
? MutationHooks<Definitions[K]>
: 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]>
: Definitions[K] extends MutationDefinition<any, any, any, any, any>
? MutationHooks<Definitions[K]>
: 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 extends QueryKeys<Definitions>>(
endpointName: EndpointName,
options?: PrefetchOptions
): (
arg: QueryArgFrom<Definitions[EndpointName]>,
options?: PrefetchOptions
) => void
} & HooksWithUniqueNames<Definitions>
}
/**
* A hook that accepts a string endpoint name, and provides a callback that when called, pre-fetches the data for that endpoint.
*/
usePrefetch<EndpointName extends QueryKeys<Definitions>>(
endpointName: EndpointName,
options?: PrefetchOptions
): (
arg: QueryArgFrom<Definitions[EndpointName]>,
options?: PrefetchOptions
) => void
}

// type RR = typeof import('react-redux')
Expand Down
23 changes: 0 additions & 23 deletions src/query/react/reactHooksCommonExports.ts

This file was deleted.

0 comments on commit d2aaff0

Please sign in to comment.