我有一个简单的异步动作创建器,它返回一个函数
export const addFiles = (files: any) => {
return (dispatch, getState) => {
files.forEach(f => {
dispatch(addFile(f));
dispatch(validateFile(f));
});
};
};
当使用这个动作与typescript时,通过调用`store.dispatch(addFiles(files))``
我收到打字稿错误
Argument of type '(dispatch: any, getState: any) => void' is not assignable to parameter of type 'Action'.
Property 'type' is missing in type '(dispatch: any, getState: any) => void'
我没有使用redux-thunk
,但我尝试将签名复制为
export type ThunkAction<R, S, E> = (dispatch: Dispatch<S>, getState: () => S,
extraArgument: E) => R;
然后将我的功能定义为
export const addFiles <ThunkAction> = (files: any)
但我仍然得到同样的错误。 有什么建议吗?
答案 0 :(得分:3)
我认为如果您使用store.dispatch<any>(addFiles(files))
答案 1 :(得分:0)
如果要避免键入(store.dispatch as ThunkDispatch<{}, {}, AnyAction>)(addFiles(files))
,请使用any
。