如何正确返回ActionSreducermap
我已经定义了像这样的还原器
import { Action, ActionReducerMap, createAction, createReducer, on } from '@ngrx/store'
import AppUser from 'src/app/shared/models/app-user';
import { AuthActions } from '../auth.action.types';
export interface AppState {
loggedInUser: AppUser
}
export const initialGlobalState: AppState = {
loggedInUser: undefined,
};
export const authReducer = createReducer(
initialGlobalState,
on(AuthActions.loginSuccess, (state, action) => {
return {
// ...state,
loggedInUser: action.loggedInUser,
};
}),
on(AuthActions.logout, (state, action) => {
return {
// ...state,
loggedInUser: undefined,
};
}),
);
export const reducers: ActionReducerMap<AppState> = {
globalState: authReducer,
};
,并且此还原器被挂入app.module.ts。
StoreModule.forRoot(reducers),
StoreDevtoolsModule.instrument({
maxAge: 25, // Retains last 25 states
logOnly: environment.production, // Restrict extension to log-only mode
}),
EffectsModule.forRoot([AuthEffects])
但是我遇到了编译错误
ts2322:类型'{GlobalState:actionReDucer&lt; AppState,Action&gt;; }'不能分配给'ActionReducermap&lt; AppState,Action&gt;'。
我在做什么错?请帮助
I have defined my reducers like this
import { Action, ActionReducerMap, createAction, createReducer, on } from '@ngrx/store'
import AppUser from 'src/app/shared/models/app-user';
import { AuthActions } from '../auth.action.types';
export interface AppState {
loggedInUser: AppUser
}
export const initialGlobalState: AppState = {
loggedInUser: undefined,
};
export const authReducer = createReducer(
initialGlobalState,
on(AuthActions.loginSuccess, (state, action) => {
return {
// ...state,
loggedInUser: action.loggedInUser,
};
}),
on(AuthActions.logout, (state, action) => {
return {
// ...state,
loggedInUser: undefined,
};
}),
);
export const reducers: ActionReducerMap<AppState> = {
globalState: authReducer,
};
and this reducer is hooked into app.module.ts like this.
StoreModule.forRoot(reducers),
StoreDevtoolsModule.instrument({
maxAge: 25, // Retains last 25 states
logOnly: environment.production, // Restrict extension to log-only mode
}),
EffectsModule.forRoot([AuthEffects])
but I am getting compile error that
TS2322: Type '{ globalState: ActionReducer<AppState, Action>; }' is not assignable to type 'ActionReducerMap<AppState, Action>'.
What am I doing wrong ? kindly help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试添加Reducer Case Case
upd@2的响应类型2
Try to add response types for reducer cases
UPD@2
我相信您需要创建另一个界面,其中设置
global
属性,可以为此index.ts
app.module.ts
I believe you need to create another interface where you set your
global
property, you could create another file for thisindex.ts
app.module.ts