export const rootReducer = combineReducers({
login: loginReducer,
});
这很好用,但只要我尝试结合另一种减速器
export const rootReducer = combineReducers({
login: loginReducer,
logout: logoutReducer
});
我开始在rootReducer上得到一个错误,
'rootReducer' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.
我该如何修改?
这就是我的logoutReducer的样子:
import {store} from '../index'
export const logoutReducer = (state = store.getState(), { type, payload } :any) => {
switch (type) {
case "logout":
return {...state, token: payload};
default:
return state;
}
};
您是否尝试过将类型分配给底层减速器?
例如:
import {Action, Reducer} from 'redux';
interface LoginState {
isLoggedIn: boolean;
token: string;
}
interface LogoutState {
token:string;
}
export const logOutReducer: Reducer<LogoutState> = (state: LogoutState | undefined, incomingAction: Action): LogoutState=> {
switch (incomingAction.type) {
case "logout":
return {...state, token: payload};
default:
return state;
}
}
//... export const logInReducer: Reducer<LoginState>...