如何在打字稿中使用 redux thunk 函数?

问题描述 投票:0回答:0

我尝试使用打字稿编写一段 thunk 函数,如下所示:

export const fetchBooks = async(dispatch:BookDispatch, getState:()=>RootState) => {
    const initBooks = await GetBooks();
    dispatch(FetchAllBooks(initBooks));
}

当我在组件中使用以下代码调用上面的thunk函数时,出现了以下错误,即使这个错误对运行没有任何影响。

store.dispatch(fetchBooks);

错误信息:

Argument of type '(dispatch: BookDispatch, getState: () => RootState) => void' 
is not assignable to parameter of type 'BookActions'.

我的问题是如何修复此错误消息?

typescript react-redux redux-thunk
© www.soinside.com 2019 - 2024. All rights reserved.