Skip to content

Commit

Permalink
fix: Default export of the module has or is using private name type e…
Browse files Browse the repository at this point in the history
…rror when using latest alpha/beta
  • Loading branch information
eric-crowell committed Jul 19, 2023
1 parent 32e9081 commit 0a19894
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
17 changes: 8 additions & 9 deletions packages/toolkit/src/createSlice.ts
Expand Up @@ -233,15 +233,14 @@ createSlice({
selectors?: Selectors
}

const reducerDefinitionType: unique symbol = Symbol.for('rtk-reducer-type')
enum ReducerType {
export enum ReducerType {
reducer = 'reducer',
reducerWithPrepare = 'reducerWithPrepare',
asyncThunk = 'asyncThunk',
}

interface ReducerDefinition<T extends ReducerType = ReducerType> {
[reducerDefinitionType]: T
_reducerDefinitionType: T
}

export interface CaseReducerDefinition<
Expand Down Expand Up @@ -375,7 +374,7 @@ export interface ReducerCreators<State> {
ReturnType<_ActionCreatorWithPreparedPayload<Prepare>>
>
): {
[reducerDefinitionType]: ReducerType.reducerWithPrepare
_reducerDefinitionType: ReducerType.reducerWithPrepare
prepare: Prepare
reducer: CaseReducer<
State,
Expand Down Expand Up @@ -748,7 +747,7 @@ function buildReducerCreators<State>(): ReducerCreators<State> {
config: AsyncThunkSliceReducerConfig<State, any>
): AsyncThunkSliceReducerDefinition<State, any> {
return {
[reducerDefinitionType]: ReducerType.asyncThunk,
_reducerDefinitionType: ReducerType.asyncThunk,
payloadCreator,
...config,
}
Expand All @@ -765,13 +764,13 @@ function buildReducerCreators<State>(): ReducerCreators<State> {
},
}[caseReducer.name],
{
[reducerDefinitionType]: ReducerType.reducer,
_reducerDefinitionType: ReducerType.reducer,
} as const
)
},
preparedReducer(prepare, reducer) {
return {
[reducerDefinitionType]: ReducerType.reducerWithPrepare,
_reducerDefinitionType: ReducerType.reducerWithPrepare,
prepare,
reducer,
}
Expand Down Expand Up @@ -813,14 +812,14 @@ function handleNormalReducerDefinition<State>(
function isAsyncThunkSliceReducerDefinition<State>(
reducerDefinition: any
): reducerDefinition is AsyncThunkSliceReducerDefinition<State, any, any, any> {
return reducerDefinition[reducerDefinitionType] === ReducerType.asyncThunk
return reducerDefinition._reducerDefinitionType === ReducerType.asyncThunk
}

function isCaseReducerWithPrepareDefinition<State>(
reducerDefinition: any
): reducerDefinition is CaseReducerWithPrepareDefinition<State, any> {
return (
reducerDefinition[reducerDefinitionType] === ReducerType.reducerWithPrepare
reducerDefinition._reducerDefinitionType === ReducerType.reducerWithPrepare
)
}

Expand Down
2 changes: 2 additions & 0 deletions packages/toolkit/src/index.ts
Expand Up @@ -67,6 +67,7 @@ export type {
export {
// js
createSlice,
ReducerType,
} from './createSlice'

export type {
Expand All @@ -78,6 +79,7 @@ export type {
ValidateSliceCaseReducers,
CaseReducerWithPrepare,
ReducerCreators,
SliceSelectors,
} from './createSlice'
export type { ActionCreatorInvariantMiddlewareOptions } from './actionCreatorInvariantMiddleware'
export { createActionCreatorInvariantMiddleware } from './actionCreatorInvariantMiddleware'
Expand Down

0 comments on commit 0a19894

Please sign in to comment.