我有一个小应用程序,我正在作为一个客户机的演示,但我在使用一个减速机时遇到了困难。我的一个摘录
AppModule
看起来像这样:
export function rootReducerFactory() {
return reducer;
}
@NgModule({
imports: [
StoreModule.forRoot({}, {
reducerFactory: rootReducerFactory
})
// other imports
],
declarations: [
// some declarations
],
providers: [
// some providers
]
})
export class WeatherModule { }
当我的减速机签名如下所示时,此功能将正常工作:
export function reducer( state: State = initialState, action: WeatherActionsUnion )
{
// reducer code
}
但是,如果我尝试强烈键入减速器的返回,如:
export function reducer( state: State = initialState, action: WeatherActionsUnion ): State
{
// reducer code
}
…,我需要做的是,我得到一个编译时错误:
错误TS2345:“{}”类型的参数不能分配给“ActionReducerMap”类型的参数InjectionToken
StoreModule.forRoot()
我在打电话。我做错什么了?
我确实试过了:
StoreModule.forRoot({
reducerFactory: rootReducerFactory
})
…虽然编译时不再有错误,但不会调用reducer。