Skip to content
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
26 changes: 26 additions & 0 deletions test/typescript/replaceReducer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { combineReducers, createStore } from 'redux'

/**
* verify that replaceReducer maintains strict typing if the new types change
*/
const bar = (state = { value: 'bar' }) => state
const baz = (state = { value: 'baz' }) => state
const ACTION = {
type: 'action'
}

const originalCompositeReducer = combineReducers({ bar })
const store = createStore(originalCompositeReducer)
store.dispatch(ACTION)

const firstState = store.getState()
firstState.bar.value
// typings:expect-error
firstState.baz.value

const nextStore = store.replaceReducer(combineReducers({ baz })) // returns -> { baz: { value: 'baz' }}

const nextState = nextStore.getState()
// typings:expect-error
nextState.bar.value
nextState.baz.value