我正在使用 redux-toolkit,并尝试发送一个 thunk。我正在使用的调度函数看起来像这样,这直接取自文档。eslint 抱怨缺少返回类型,知道它应该是什么吗?
export const useAppDispatch = () => useDispatch<AppDispatch>();
Run Code Online (Sandbox Code Playgroud)
此外,我得到了同样的错误,如这个问题How to split an Action or a ThunkAction (in TypeScript, with redux-thunk)? ,但据我了解,没有真正的解决方案。
所以如果我得到这样的代码:
export const fetchSomeThing = createAsyncThunk<SomeType[]>('someThing/fetch', async () => {
const someClient = useSomeClient();
const someThing: SomeType[] = await someClient.listSomething();
return someThing;
});
// I also tried typing dispatch as AppDispatch here explicitly, but it gives me the same error
const dispatch = useAppDispatch();
dispatch(fetchSomeThing()) //This gives an error: Property 'type' is missing in type …Run Code Online (Sandbox Code Playgroud)