Skip to content

Commit

Permalink
add mhelmerson example
Browse files Browse the repository at this point in the history
  • Loading branch information
cellog committed Aug 28, 2019
1 parent 55f4b4d commit 8ed803d
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion test/typescript/enhancers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PreloadedState } from '../../index'
import { PreloadedState, Store } from '../../index'
import { StoreEnhancer, Action, AnyAction, Reducer, createStore } from 'redux'

interface State {
Expand Down Expand Up @@ -103,3 +103,43 @@ function replaceReducerExtender() {
// typings:expect-error
store.wrongMethod()
}

function mhelmersonExample() {
interface State {
someField: 'string'
}

interface ExtraState {
extraField: 'extra'
}

const reducer: Reducer<State> = null as any

function stateExtensionExpectedToWork() {
interface ExtraState {
extraField: 'extra'
}

const enhancer: StoreEnhancer<{}, ExtraState> = createStore => <
S,
A extends Action = AnyAction
>(
reducer: Reducer<S, A>,
preloadedState?: PreloadedState<S>
) => {
const wrappedReducer: Reducer<S & ExtraState, A> = null as any
const wrappedPreloadedState: PreloadedState<S & ExtraState> = null as any
const store = createStore(wrappedReducer, wrappedPreloadedState)
return {
...store,
replaceReducer: (nextReducer: Reducer<S, A>) => {
const nextWrappedReducer: Reducer<S & ExtraState, A> = null as any
return store.replaceReducer(nextWrappedReducer)
}
} as Store<S & ExtraState, A, ExtraState>
}

const store = createStore(reducer, enhancer)
store.replaceReducer(reducer)
}
}

0 comments on commit 8ed803d

Please sign in to comment.