Platform: Issue with typings in store module

Created on 21 Jul 2017  路  2Comments  路  Source: ngrx/platform

While looking into #141, I noticed that there is an issue with the typings in the forFeature method of StoreModule.
https://github.com/ngrx/platform/blob/master/modules/store/src/store_module.ts#L124-L133

static forFeature<T, V extends Action = Action>(
    featureName: string,
    reducers: ActionReducerMap<T, V>,
    config?: StoreConfig<T, V>
  ): ModuleWithProviders;
  static forFeature<T, V extends Action = Action>(
    featureName: string,
    reducer: ActionReducer<T, V>,
    config?: StoreConfig<T, V>
  ): ModuleWithProviders;

Note that in the second definition, the second parameter is called reducer, a variable that is not used in the function at all. I'm not sure what the intention is here, so I'm not sure how to fix it.

If that is intended to be reducers, allowing reducers to be an ActionReducer, I think the type of reducers in the first section could be amended to ActionReducerMap<T, V> | ActionReducer<T, V>, and the second section could be omitted. Or, if it is intended that reducers should be an ActionReducerMap only, the second section could also be omitted.

Most helpful comment

You can provide a single reducer instead of a map of reducers for the feature. See https://github.com/ngrx/platform/issues/34

StoreModule.forFeature('feature', featureReducer);

or

StoreModule.forFeature('feature', featureReducerMap);

All 2 comments

You can provide a single reducer instead of a map of reducers for the feature. See https://github.com/ngrx/platform/issues/34

StoreModule.forFeature('feature', featureReducer);

or

StoreModule.forFeature('feature', featureReducerMap);

@brandonroberts Thanks for the clarification! My confusion was that I didn't understand that the names of parameters in overloaded functions didn't have to be the same as the names in the actual function. It might have been slightly clearer (but more awkward) if the second parameter of the actual function declaration for forFeature were reducerOrReducers, since, as you say, is can be either.

Was this page helpful?
0 / 5 - 0 ratings