Skip to content

Commit 6d96545

Browse files
cellogtimdorr
authored andcommitted
fix typings of createStore and import of Reducer type (#3555)
1 parent 65afa45 commit 6d96545

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/createStore.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export default function createStore<S, A extends Action, Ext, StateExt>(
5050
reducer: Reducer<S, A>,
5151
preloadedState?: PreloadedState<S> | StoreEnhancer<Ext, StateExt>,
5252
enhancer?: StoreEnhancer<Ext>
53-
) {
53+
): Store<S & StateExt, A> & Ext {
5454
if (
5555
(typeof preloadedState === 'function' && typeof enhancer === 'function') ||
5656
(typeof enhancer === 'function' && typeof arguments[3] === 'function')
@@ -72,7 +72,9 @@ export default function createStore<S, A extends Action, Ext, StateExt>(
7272
throw new Error('Expected the enhancer to be a function.')
7373
}
7474

75-
return enhancer(createStore)(reducer, preloadedState as PreloadedState<S>)
75+
return enhancer(createStore)(reducer, preloadedState as PreloadedState<
76+
S
77+
>) as Store<S & StateExt, A> & Ext
7678
}
7779

7880
if (typeof reducer !== 'function') {
@@ -315,12 +317,12 @@ export default function createStore<S, A extends Action, Ext, StateExt>(
315317
// the initial state tree.
316318
dispatch({ type: ActionTypes.INIT } as A)
317319

318-
const store: Store<S, A> = ({
320+
const store: Store<S & StateExt, A> & Ext = ({
319321
dispatch: dispatch as Dispatch<A>,
320322
subscribe,
321323
getState,
322324
replaceReducer,
323325
[$$observable]: observable
324-
} as unknown) as Store<S, A>
326+
} as unknown) as Store<S & StateExt, A> & Ext
325327
return store
326328
}

0 commit comments

Comments
 (0)