在以下情况下,在UserAction.LOGOUT_REQUESTED的情况下,我需要返回null。我该怎么做?或者有更好的方法吗?
public static reducer(state: ILoginReducerState = UserReducer.initialState, action: ILogInAction): ILoginReducerState {
switch (action.type) {
case UserAction.LOGOUT_REQUESTED:
return null}
ILoginReducerState定义如下
export interface IlogIn
{
userName : string,
password:string,
error:boolean
}
export interface ILoginReducerState
{
readonly loading: boolean
readonly currentUser: IlogIn
readonly errors?: string
}
现在我遇到错误[ts]类型'null'无法分配给类型'ILoginReducerState'。
private static readonly initialState: ILoginReducerState = {
currentUser: {
error:false,
password:'',
userName:'',
},
errors:'',
loading: false,
};