【发布时间】:2020-10-01 14:09:32
【问题描述】:
我正在尝试使用 next-redux-wrapper 商店从 Next.js 中的 getServerSideProps 发送 thunk。但是,我不断收到以下打字稿错误:
TS2345: Argument of type '(dispatch: any) => Promise<any>' is not assignable to parameter of type 'AnyAction'. Property 'type' is missing in type '(dispatch: any) => Promise<any>' but required in type 'AnyAction'.
我之前没有在 Redux 中使用过 TypeScript,所以不确定我在这里做错了什么......
我的代码如下:
// page.tsx
export const getServerSideProps = wrapper.getServerSideProps(
async ({ store, params }) => {
store.dispatch(myThunkFunction(params.id));
return {
props: {
id: params.id,
},
};
});
// thunks.ts
export const myThunkFunction = id => {
return async dispatch => {
...
};
};
【问题讨论】:
标签: reactjs typescript redux next.js redux-thunk