Skip to content

Commit

Permalink
Fix duplicate types
Browse files Browse the repository at this point in the history
# Conflicts:
#	packages/toolkit/src/query/endpointDefinitions.ts
#	packages/toolkit/src/query/react/buildHooks.ts
  • Loading branch information
aryaemami59 authored and markerikson committed Oct 27, 2024
1 parent 2717292 commit 369d95c
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 95 deletions.
10 changes: 5 additions & 5 deletions packages/toolkit/src/query/core/apiState.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type { SerializedError } from '@reduxjs/toolkit'
import type { BaseQueryError } from '../baseQueryTypes'
import type {
QueryDefinition,
MutationDefinition,
EndpointDefinitions,
BaseEndpointDefinition,
ResultTypeFrom,
QueryArgFrom,
EndpointDefinitions,
InfiniteQueryDefinition,
MutationDefinition,
PageParamFrom,
QueryArgFrom,
QueryDefinition,
ResultTypeFrom,
} from '../endpointDefinitions'
import type { Id, WithRequiredProp } from '../tsHelpers'

Expand Down
2 changes: 1 addition & 1 deletion packages/toolkit/src/query/core/buildInitiate.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type {
SafePromise,
SerializedError,
ThunkAction,
ThunkDispatch,
UnknownAction,
} from '@reduxjs/toolkit'
import type { Dispatch } from 'redux'
import type { SafePromise } from '../../tsHelpers'
import { asSafePromise } from '../../tsHelpers'
import type { Api, ApiContext } from '../apiTypes'
import type { BaseQueryError, QueryReturnValue } from '../baseQueryTypes'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,12 @@ export type CacheLifecycleInfiniteQueryExtraOptions<
QueryArg,
BaseQuery extends BaseQueryFn,
ReducerPath extends string = string,
> = {
onCacheEntryAdded?(
arg: QueryArg,
api: QueryCacheLifecycleApi<QueryArg, BaseQuery, ResultType, ReducerPath>,
): Promise<void> | void
}
> = CacheLifecycleQueryExtraOptions<
ResultType,
QueryArg,
BaseQuery,
ReducerPath
>

export type CacheLifecycleMutationExtraOptions<
ResultType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ export type QueryLifecycleInfiniteQueryExtraOptions<
QueryArg,
BaseQuery extends BaseQueryFn,
ReducerPath extends string = string,
> = {
onQueryStarted?(
arg: QueryArg,
api: QueryLifecycleApi<QueryArg, BaseQuery, ResultType, ReducerPath>,
): Promise<void> | void
}
> = QueryLifecycleQueryExtraOptions<
ResultType,
QueryArg,
BaseQuery,
ReducerPath
>

export type QueryLifecycleMutationExtraOptions<
ResultType,
Expand Down
19 changes: 11 additions & 8 deletions packages/toolkit/src/query/core/buildSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,17 @@ export function buildSlice({
substate.startedTimeStamp = meta.startedTimeStamp

// TODO: Awful - fix this most likely by just moving it to its own slice that only works on InfQuery's
if ('param' in substate && 'direction' in substate) {
if ('param' in arg && 'direction' in arg) {
substate.param = arg.param
substate.direction = arg.direction as
| 'forward'
| 'backwards'
| undefined
}
if (
'param' in substate &&
'direction' in substate &&
'param' in arg &&
'direction' in arg
) {
substate.param = arg.param
substate.direction = arg.direction as
| 'forward'
| 'backwards'
| undefined
}
})
}
Expand Down
7 changes: 6 additions & 1 deletion packages/toolkit/src/query/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ export const createApi = /* @__PURE__ */ buildCreateApi(coreModule())
export { QueryStatus } from './apiState'
export type {
CombinedState,
InfiniteData,
InfiniteQueryConfigOptions,
InfiniteQuerySubState,
MutationKeys,
QueryCacheKey,
QueryKeys,
Expand All @@ -14,6 +17,7 @@ export type {
SubscriptionOptions,
} from './apiState'
export type {
InfiniteQueryActionCreatorResult,
MutationActionCreatorResult,
QueryActionCreatorResult,
StartQueryActionCreatorOptions,
Expand All @@ -24,7 +28,7 @@ export type {
QueryCacheLifecycleApi,
QueryLifecycleApi,
SubscriptionSelectors,
} from './buildMiddleware'
} from './buildMiddleware/index'
export { skipToken } from './buildSelectors'
export type {
InfiniteQueryResultSelectorResult,
Expand All @@ -40,6 +44,7 @@ export type {
} from './buildThunks'
export { coreModuleName } from './module'
export type {
ApiEndpointInfiniteQuery,
ApiEndpointMutation,
ApiEndpointQuery,
CoreModule,
Expand Down
11 changes: 5 additions & 6 deletions packages/toolkit/src/query/endpointDefinitions.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import type { Api } from '@reduxjs/toolkit/query'
import type {
InfiniteQueryConfigOptions,
QuerySubState,
RootState,
} from './core/apiState'
import type {
BaseQueryApi,
BaseQueryArg,
Expand All @@ -25,6 +20,11 @@ import type {
QueryLifecycleMutationExtraOptions,
QueryLifecycleQueryExtraOptions,
} from './core/buildMiddleware/queryLifecycle'
import type {
InfiniteQueryConfigOptions,
QuerySubState,
RootState,
} from './core/index'
import type { SerializeQueryArgs } from './defaultSerializeQueryArgs'
import type { NEVER } from './fakeBaseQuery'
import type {
Expand All @@ -43,7 +43,6 @@ type EndpointDefinitionWithQuery<
QueryArg,
BaseQuery extends BaseQueryFn,
ResultType,
PageParam = never,
> = {
/**
* `query` can be a function that returns either a `string` or an `object` which is passed to your `baseQuery`. If you are using [fetchBaseQuery](./fetchBaseQuery), this can return either a `string` or an `object` of properties in `FetchArgs`. If you use your own custom [`baseQuery`](../../rtk-query/usage/customizing-queries), you can customize this behavior to your liking.
Expand Down
100 changes: 49 additions & 51 deletions packages/toolkit/src/query/index.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
// This must remain here so that the `mangleErrors.cjs` build script
// does not have to import this into each source file it rewrites.
import { formatProdErrorMessage } from '@reduxjs/toolkit'

export type {
CombinedState,
InfiniteData,
InfiniteQueryConfigOptions,
QueryCacheKey,
QueryKeys,
QuerySubState,
RootState,
SubscriptionOptions,
} from './core/apiState'
export { QueryStatus } from './core/apiState'
export type { Api, ApiContext, Module } from './apiTypes'

export type {
BaseQueryApi,
BaseQueryArg,
Expand All @@ -26,67 +13,78 @@ export type {
BaseQueryResult,
QueryReturnValue,
} from './baseQueryTypes'
export {
QueryStatus,
coreModule,
coreModuleName,
createApi,
setupListeners,
skipToken,
} from './core/index'
export type {
ApiEndpointInfiniteQuery,
ApiEndpointMutation,
ApiEndpointQuery,
CombinedState,
CoreModule,
InfiniteData,
InfiniteQueryActionCreatorResult,
InfiniteQueryConfigOptions,
InfiniteQueryResultSelectorResult,
MutationActionCreatorResult,
MutationResultSelectorResult,
PrefetchOptions,
QueryActionCreatorResult,
QueryCacheKey,
QueryKeys,
QueryResultSelectorResult,
QuerySubState,
RootState,
SkipToken,
StartQueryActionCreatorOptions,
SubscriptionOptions,
} from './core/index'
export type { ApiModules } from './core/module'
export { buildCreateApi } from './createApi'
export type { CreateApi, CreateApiOptions } from './createApi'
export { defaultSerializeQueryArgs } from './defaultSerializeQueryArgs'
export type { SerializeQueryArgs } from './defaultSerializeQueryArgs'
export type {
BaseEndpointDefinition,
EndpointDefinitions,
EndpointDefinition,
DefinitionType,
DefinitionsFromApi,
EndpointBuilder,
QueryDefinition,
EndpointDefinition,
EndpointDefinitions,
InfiniteQueryArgFrom,
InfiniteQueryDefinition,
InfiniteQueryExtraOptions,
MutationDefinition,
MutationExtraOptions,
TagDescription,
OverrideResultType,
PageParamFrom,
QueryArgFrom,
QueryDefinition,
QueryExtraOptions,
ResultTypeFrom,
DefinitionType,
DefinitionsFromApi,
OverrideResultType,
ResultDescription,
ResultTypeFrom,
TagDescription,
TagTypesFromApi,
UpdateDefinitions,
} from './endpointDefinitions'
export { _NEVER, fakeBaseQuery } from './fakeBaseQuery'
export { fetchBaseQuery } from './fetchBaseQuery'
export type {
FetchArgs,
FetchBaseQueryArgs,
FetchBaseQueryError,
FetchBaseQueryMeta,
FetchArgs,
} from './fetchBaseQuery'
export { retry } from './retry'
export type { RetryOptions } from './retry'
export { setupListeners } from './core/setupListeners'
export { skipToken } from './core/buildSelectors'
export type {
QueryResultSelectorResult,
MutationResultSelectorResult,
SkipToken,
} from './core/buildSelectors'
export type {
InfiniteQueryActionCreatorResult,
QueryActionCreatorResult,
MutationActionCreatorResult,
StartQueryActionCreatorOptions,
} from './core/buildInitiate'
export type { CreateApi, CreateApiOptions } from './createApi'
export { buildCreateApi } from './createApi'
export { _NEVER, fakeBaseQuery } from './fakeBaseQuery'
export { copyWithStructuralSharing } from './utils/copyWithStructuralSharing'
export { createApi, coreModule, coreModuleName } from './core'
export type {
ApiEndpointMutation,
ApiEndpointQuery,
ApiEndpointInfiniteQuery,
ApiModules,
CoreModule,
PrefetchOptions,
} from './core/module'
export { defaultSerializeQueryArgs } from './defaultSerializeQueryArgs'
export type { SerializeQueryArgs } from './defaultSerializeQueryArgs'

export type {
Id as TSHelpersId,
NoInfer as TSHelpersNoInfer,
Override as TSHelpersOverride,
} from './tsHelpers'
export { copyWithStructuralSharing } from './utils/copyWithStructuralSharing'
21 changes: 11 additions & 10 deletions packages/toolkit/src/query/react/buildHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ import type {
BaseQueryFn,
CoreModule,
EndpointDefinitions,
InfiniteData,
InfiniteQueryActionCreatorResult,
InfiniteQueryConfigOptions,
InfiniteQueryArgFrom,
InfiniteQueryDefinition,
InfiniteQueryResultSelectorResult,
MutationActionCreatorResult,
MutationDefinition,
MutationResultSelectorResult,
PageParamFrom,
PrefetchOptions,
QueryActionCreatorResult,
QueryArgFrom,
Expand All @@ -36,7 +37,11 @@ import type {
TSHelpersNoInfer,
TSHelpersOverride,
} from '@reduxjs/toolkit/query'
import { QueryStatus, skipToken } from '@reduxjs/toolkit/query'
import {
defaultSerializeQueryArgs,
QueryStatus,
skipToken,
} from '@reduxjs/toolkit/query'
import type { DependencyList } from 'react'
import {
useCallback,
Expand All @@ -48,13 +53,9 @@ import {
useState,
} from 'react'
import { shallowEqual } from 'react-redux'
import type { InfiniteQueryResultSelectorResult } from '../core/buildSelectors'
import type { SubscriptionSelectors } from '../core/index'
import { defaultSerializeQueryArgs } from '../defaultSerializeQueryArgs'
import type {
InfiniteQueryArgFrom,
PageParamFrom,
} from '../endpointDefinitions'

import type { SubscriptionSelectors } from '../core/buildMiddleware/index'
import type { InfiniteData, InfiniteQueryConfigOptions } from '../core/index'
import type { UninitializedValue } from './constants'
import { UNINITIALIZED_VALUE } from './constants'
import type { ReactHooksModuleOptions } from './module'
Expand Down
2 changes: 1 addition & 1 deletion packages/toolkit/src/query/react/namedHooks.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { UseMutation, UseLazyQuery, UseQuery } from './buildHooks'
import type {
DefinitionType,
EndpointDefinitions,
MutationDefinition,
QueryDefinition,
} from '@reduxjs/toolkit/query'
import type { UseLazyQuery, UseMutation, UseQuery } from './buildHooks'

type QueryHookNames<Definitions extends EndpointDefinitions> = {
[K in keyof Definitions as Definitions[K] extends {
Expand Down

0 comments on commit 369d95c

Please sign in to comment.