Typescript 为redux操作创建者键入

Typescript 为redux操作创建者键入,typescript,redux,redux-thunk,Typescript,Redux,Redux Thunk,我目前对我正在开发的react redux应用程序中的动作创建者类型感到困惑。我让这个动作创建者在等式的两边都有类型,TS编译器说一切都很完美: const setItem: ActionCreator<ThunkResult<void>> = (...): ThunkResult<void> => (...): void => { dispatch({ ... }); }; const setItem:ActionCreator

我目前对我正在开发的react redux应用程序中的动作创建者类型感到困惑。我让这个动作创建者在等式的两边都有类型,TS编译器说一切都很完美:

const setItem: ActionCreator<ThunkResult<void>> = (...): ThunkResult<void> => (...): void => {
  dispatch({
    ...
  });
};
const setItem:ActionCreator=(…):ThunkResult=>(…):void=>{
派遣({
...
});
};
其中ThunkResult为
ThunkResult=ThunkAction

我不清楚的是,为什么左侧返回的函数类型是
ActionCreator
,而右侧返回的函数类型是
ThunkResult

注意:我跳过了args,因为它们在这个问题中并不重要


我不确定这是误解还是TS中的问题。

我可以让您更容易理解 首先,只要想想ActionCreator是一种类型,而且它将是

type ActionCreator=(参数):T=>T
//然后可以定义变量
常量setItem:ActionCreator=(参数):字符串=>“”
喜欢ThunkResult

type ThunkResult=(参数):T=>T
//然后可以定义变量
常量thunk:ThunkResult=(参数):数字=>0
所以,如果你把它们混合在一起,就会是这样

ActionCreator=(参数):ThunkResult=>ThunkResult
//及
ThunkResult=(参数):void=>void
//所以
ActionCreator=(params):ThunkResult=>(params2):void=>void//只需将上面的ThunkResult替换为(params):void=>void

希望它能有所帮助

那么我做对了吗?基本上ActionCreator和ThunkResult都有一种“函数”类型,而不是这些函数的返回值类型?完全正确。:--)