-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Description
According to the documentation, the metaReducer property of the store configuration expects an array of functions that accept the reducer and return a reducer function.
function debug(reducer) {
return function(state, action) {
console.log('state', state);
console.log('action', action);
return reducer(state, action);
}
}
const metaReducers = [debug];
@NgModule({
imports: [
StoreModule.forRoot(reducers, { metaReducers })
]
})https://github.com/ngrx/platform/blob/master/docs/store/api.md#meta-reducers
I tested this using this code...
StoreModule.forRoot(REDUCERS_TOKEN, {
metaReducers: [
(...args) => console.log(args)
]
}),... and the browser console confirms this:
However, when I want to actually implement the code from the documentation, I get typing issues.
[ts]
Argument of type '{ metaReducers: ((reducer: AppState) => (state: any, action: any) => any)[]; }' is not assignable to parameter of type 'StoreConfig<AppState, Action>'.
Types of property 'metaReducers' are incompatible.
Type '((reducer: AppState) => (state: any, action: any) => any)[]' is not assignable to type 'ActionReducer<AppState, Action>[]'.
Type '(reducer: AppState) => (state: any, action: any) => any' is not assignable to type 'ActionReducer<AppState, Action>'.
Type '(state: any, action: any) => any' is not assignable to type 'AppState'.
From what I see, the StoreConfig interface incorrectly defines metaReducers as ActionReducer<any, any>[];
export interface StoreFeature<T, V extends Action = Action> { key: string;
reducers: ActionReducerMap<T, V> | ActionReducer<T, V>;
reducerFactory: ActionReducerFactory<T, V>;
initialState?: InitialState<T>;
metaReducers?: ActionReducer<any, any>[];
}platform/modules/store/src/models.ts
Line 29 in d2295c7
| metaReducers?: ActionReducer<any, any>[]; |
From what I understand the correct typing should be ActionReducer<T, V>[].
Can anyone confirm this?
Update
Here's a repo to reproduce this issue:
https://github.com/luchsamapparat/ngrx-meta-reducer-issue
Just run npm install and then npm start
