()
| 194 | const reducer: Reducer<State> = null as any |
| 195 | |
| 196 | function stateExtensionExpectedToWork() { |
| 197 | interface ExtraState { |
| 198 | extraField: string |
| 199 | } |
| 200 | |
| 201 | const enhancer: StoreEnhancer<{}, ExtraState> = |
| 202 | createStore => |
| 203 | <S, A extends Action, PreloadedState>( |
| 204 | reducer: Reducer<S, A, PreloadedState>, |
| 205 | preloadedState?: PreloadedState | undefined |
| 206 | ) => { |
| 207 | const wrappedReducer: Reducer< |
| 208 | S & ExtraState, |
| 209 | A, |
| 210 | PreloadedState & ExtraState |
| 211 | > = (state, action) => { |
| 212 | const newState = reducer(state, action) |
| 213 | return { |
| 214 | ...newState, |
| 215 | extraField: 'extra' |
| 216 | } |
| 217 | } |
| 218 | const wrappedPreloadedState = preloadedState |
| 219 | ? { |
| 220 | ...preloadedState, |
| 221 | extraField: 'extra' |
| 222 | } |
| 223 | : undefined |
| 224 | const store = createStore(wrappedReducer, wrappedPreloadedState) |
| 225 | return { |
| 226 | ...store, |
| 227 | replaceReducer(nextReducer: Reducer<S, A>) { |
| 228 | const nextWrappedReducer: Reducer<S & ExtraState, A> = ( |
| 229 | state, |
| 230 | action |
| 231 | ) => { |
| 232 | const newState = nextReducer(state, action) |
| 233 | return { |
| 234 | ...newState, |
| 235 | extraField: 'extra' |
| 236 | } |
| 237 | } |
| 238 | return store.replaceReducer(nextWrappedReducer) |
| 239 | } |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | interface PartialState { |
| 244 | someField?: 'string' |
| 245 | test?: boolean |
| 246 | } |
| 247 | |
| 248 | const initialReducer: Reducer<PartialState, Action> = () => ({ |
| 249 | someField: 'string' |
| 250 | }) |
| 251 | const store = createStore<PartialState, Action, {}, ExtraState>( |
| 252 | initialReducer, |
| 253 | enhancer |
nothing calls this directly
no test coverage detected
searching dependent graphs…