Redux 工具包,调度 thunk 类型丢失

Redux toolkit, dispatching thunk type missing

我正在使用 redux-toolkit,并尝试发送 thunk。 我正在使用的调度函数看起来像这样,这是直接从文档中获取的。 eslint 抱怨缺少 return 类型,知道它应该是什么吗?

export const useAppDispatch = () => useDispatch<AppDispatch>();

此外,我得到了与这个问题 中相同的错误,但据我所知,那里没有真正的解决方案。

所以如果我得到这样的代码:

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 'AsyncThunkAction<SomeType[], void, {}>' 
// but required in type 'AnyAction'.ts(2345), index.d.ts(21, 3): 'type' is declared here.

我的店铺是这样的:

export const store = configureStore({
  reducer: {
    someThing: someThingReducer,
  },
});

// Infer the `RootState` and `AppDispatch` types from the store itself
export type RootState = ReturnType<typeof store.getState>;
export type AppDispatch = typeof store.dispatch; // According to vs-code this is of type AppDispatch = Dispatch<AnyAction>

这似乎最近发生在人们以某种​​方式并排安装 redux@4.0.5redux@4.1.0 时,通常可以通过重新安装 @types/react-redux 来解决 npm i @types/react-reduxyarn add @types/react-redux。你能试试吗?