8000 fix typings of createStore and import of Reducer type by cellog · Pull Request #3555 · reduxjs/redux · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix typings of createStore and import of Reducer type #3555

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/createStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import $$observable from 'symbol-observable'

import {
Store,
Reducer,
PreloadedState,
StoreEnhancer,
Dispatch,
Observer
} from '..'
} from './types/store'
import { Action } from './types/actions'
import { Reducer } from './types/reducers'
import ActionTypes from './utils/actionTypes'
import isPlainObject from './utils/isPlainObject'

Expand Down Expand Up @@ -50,7 +50,7 @@ export default function createStore<S, A extends Action, Ext, StateExt>(
reducer: Reducer<S, A>,
preloadedState?: PreloadedState<S> | StoreEnhancer<Ext, StateExt>,
enhancer?: StoreEnhancer<Ext>
) {
): Store<S & StateExt, A> & Ext {
if (
(typeof preloadedState === 'function' && typeof enhancer === 'function') ||
(typeof enhancer === 'function' && typeof arguments[3] === 'function')
Expand All @@ -72,7 +72,9 @@ export default function createStore<S, A extends Action, Ext, StateExt>(
throw new Error('Expected the enhancer to be a function.')
}

return enhancer(createStore)(reducer, preloadedState as PreloadedState<S>)
return enhancer(createStore)(reducer, preloadedState as PreloadedState<
S
>) as Store<S & StateExt, A> & Ext
}

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

const store: Store<S, A> = ({
const store: Store<S & StateExt, A> & Ext = ({
dispatch: dispatch as Dispatch<A>,
subscribe,
getState,
replaceReducer,
[$$observable]: observable
} as unknown) as Store<S, A>
} as unknown) as Store<S & StateExt, A> & Ext
return store
}
0