我正在使用typesafe-actions
,并且想要创建一个根缩减程序,它将允许我处理像LOGGED_OUT
这样的全局操作,以便清除状态。就像在answer to this question里一样。
我尝试了一些方法,但我一直失去了typesafe-actions
提供的类型安全性,reducer恢复为any
类型。
我有一个非常普通的类型安全操作设置。我没有发布我尝试过的隐式类型的排列解决方案,因为我认为它不会增加问题的清晰度。
我能找到的最接近解决方案的是this thread。类型安全操作的维护者自己发布了一个响应,并提到他已经有了解决方案,尽管从那时起没有提供任何链接或参考。
任何帮助都是最好的。
根据记录,我可以让它按照我发布的Stack overflow问题的模式工作,但是类型被破坏了。
发布于 2020-04-27 17:11:48
原来我在9个月前已经在一个单独的项目中解决了这个问题,但是忘记了。
import { combineReducers } from 'redux';
import auth from '../modules/auth/reducer';
import feed from '../modules/feed/reducer';
import post from '../modules/post/reducer';
import profile from '../modules/profile/reducer';
import { StateType, Reducer, RootAction } from 'typesafe-actions';
import { signOut } from 'modules/auth/actions';
const appReducer = combineReducers({
auth,
feed,
post,
profile
});
type RootState = StateType<typeof appReducer>;
const clearOnSignOutReducer: Reducer<RootState, RootAction> = (
state,
action
) => {
if (action.type === signOut().type) {
state = undefined;
}
return appReducer(state, action);
};
export default clearOnSignOutReducer;
https://stackoverflow.com/questions/61403725
复制相似问题