You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#2773 claims to have fixed #1648 and to allow to properly type a storeEnhancer that extends the state.
But it seems to not be sufficient when the enhancer adds some extra preloaded state as well.
Actually, there is a sign of that issue in the dedicated test, which uses any to type the preloaded state.
Another related problem is that the Reducer type does not seem to make sense for an "extra" reducer added through a storeEnhancer.
Indeed, the state the "extra" reducer receives will never be undefined as it will be the result of the initialization after the original reducer is applied.
So state initialization for such an "extra" reducer can only be handled through preloaded state, and not though defining a default state input in the reducer function definition.
// Initialization
// `preloadedState` is possibly undefined.
const nextState = originalReducer(preloadedState, initAction);
// At this stage, `nextState` is not `undefined`.
const extendedState = extraReducer(nextState, initAction);
Steps to Reproduce
This example showcases two TypeScript errors that occur when trying to extend the state and the preloaded state.
The code is inspired from the current test.
What is the expected behavior?
I would expect to be able to avoid the two TypeScript errors in the sandbox above, without resorting to casting or using any.
In particular for the first one, I would expect PreloadedState<S1> & PreloadedState<S2> to be assignable to PreloadedState<S1 & S2>.
I would also expect to be able to use Reducer to type an "extra" reducer added through a store enhancer.
Context
The context is to modularize the Redux store of a module-federated application.
We build a host application that uses Redux for state management and want to allow clients to define extensions to this application.
We were thinking of using storeEnhancer to be able to consume and extend the host application state from an extension.
We are not ruling out other ideas like reducer injection, but it seems less generic than using the storeEnhancer higher-order function, and in particular this would mean that extensions do not have control over the preloaded state and the middlewares.
We also don't need the extensions to inject their reducers at different points in time: we activate all extensions at the same time when the application starts.
Environment Details
Redux 4.1.2
The text was updated successfully, but these errors were encountered:
Prior Issues
#1648 #3482
What is the current behavior?
#2773 claims to have fixed #1648 and to allow to properly type a
storeEnhancer
that extends the state.But it seems to not be sufficient when the enhancer adds some extra preloaded state as well.
Actually, there is a sign of that issue in the dedicated test, which uses
any
to type the preloaded state.Another related problem is that the
Reducer
type does not seem to make sense for an "extra" reducer added through astoreEnhancer
.Indeed, the state the "extra" reducer receives will never be
undefined
as it will be the result of the initialization after the original reducer is applied.So state initialization for such an "extra" reducer can only be handled through preloaded state, and not though defining a default state input in the reducer function definition.
Steps to Reproduce
This example showcases two TypeScript errors that occur when trying to extend the state and the preloaded state.
The code is inspired from the current test.
What is the expected behavior?
I would expect to be able to avoid the two TypeScript errors in the sandbox above, without resorting to casting or using
any
.In particular for the first one, I would expect
PreloadedState<S1> & PreloadedState<S2>
to be assignable toPreloadedState<S1 & S2>
.I would also expect to be able to use
Reducer
to type an "extra" reducer added through a store enhancer.Context
The context is to modularize the Redux store of a module-federated application.
We build a host application that uses Redux for state management and want to allow clients to define extensions to this application.
We were thinking of using
storeEnhancer
to be able to consume and extend the host application state from an extension.We are not ruling out other ideas like reducer injection, but it seems less generic than using the
storeEnhancer
higher-order function, and in particular this would mean that extensions do not have control over the preloaded state and the middlewares.We also don't need the extensions to inject their reducers at different points in time: we activate all extensions at the same time when the application starts.
Environment Details
Redux 4.1.2
The text was updated successfully, but these errors were encountered: