-
-
Notifications
You must be signed in to change notification settings - Fork 15.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert adding the store as a return type to replaceReducer
- Loading branch information
1 parent
6294ad2
commit ebe6915
Showing
8 changed files
with
193 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { | ||
Action, | ||
ActionFromReducersMapObject, | ||
combineReducers, | ||
Reducer, | ||
ReducersMapObject | ||
} from '../..' | ||
|
||
/** | ||
* The existing `Reducer` type assumes that the input state is `S` or `undefined`. This works for most cases, but | ||
* `combineReducers` allows for properties in the input state to be missing. This type allows for that scenario and is | ||
* used by `combineReducersAccuratelyTyped`. It can be removed if the `Reducer` type in the core library is updated to | ||
* allow for this scenario. | ||
*/ | ||
export type ReducerThatAllowsForPartialInputState< | ||
S extends InputState, | ||
A extends Action<unknown>, | ||
InputState | ||
> = (state: InputState, action: A) => S | ||
|
||
type ReducersMapObjectThatAllowsForPartialInputState< | ||
S extends InputState, | ||
A extends Action<unknown>, | ||
InputState | ||
> = { | ||
[K in keyof InputState]: ReducerThatAllowsForPartialInputState< | ||
S[K], | ||
A, | ||
InputState[K] | ||
> | ||
} | ||
|
||
type StateFromReducersMapObjectThatAllowsForPartialInputState< | ||
M extends ReducersMapObjectThatAllowsForPartialInputState< | ||
unknown, | ||
Action<unknown>, | ||
unknown | ||
> | ||
> = { | ||
[P in keyof M]: M[P] extends Reducer<infer S, any> ? S : never | ||
} | ||
|
||
/** | ||
* The `combineReducers` function creates a reducer that allows for missing properties in the input state at the | ||
* top-level, but the types do not accurately reflect that. This method provides accurate types for | ||
* `combineReducers` in order to get the tests that use `replaceReducer` to type-check successfully. This can be | ||
* removed if the types for `combineReducers` are fixed. | ||
*/ | ||
export function combineReducersAccuratelyTyped<M extends ReducersMapObject>( | ||
reducers: M | ||
): ( | ||
state: | ||
| Partial<StateFromReducersMapObjectThatAllowsForPartialInputState<M>> | ||
| undefined, | ||
action: ActionFromReducersMapObject<M> | ||
) => StateFromReducersMapObjectThatAllowsForPartialInputState<M> { | ||
// @ts-ignore | ||
return combineReducers(reducers) | ||
} |
Oops, something went wrong.