Skip to content

Commit c9be4fd

Browse files
cellogtimdorr
authored andcommitted
add a new test to verify replaceReducer typings work (reduxjs#3521)
Former-commit-id: 5babea9
1 parent 21540b4 commit c9be4fd

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

test/typescript/replaceReducer.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { combineReducers, createStore } from 'redux'
2+
3+
/**
4+
* verify that replaceReducer maintains strict typing if the new types change
5+
*/
6+
const bar = (state = { value: 'bar' }) => state
7+
const baz = (state = { value: 'baz' }) => state
8+
const ACTION = {
9+
type: 'action'
10+
}
11+
12+
const originalCompositeReducer = combineReducers({ bar })
13+
const store = createStore(originalCompositeReducer)
14+
store.dispatch(ACTION)
15+
16+
const firstState = store.getState()
17+
firstState.bar.value
18+
// typings:expect-error
19+
firstState.baz.value
20+
21+
const nextStore = store.replaceReducer(combineReducers({ baz })) // returns -> { baz: { value: 'baz' }}
22+
23+
const nextState = nextStore.getState()
24+
// typings:expect-error
25+
nextState.bar.value
26+
nextState.baz.value

0 commit comments

Comments
 (0)