next js 和 next-redux-wrapper 的 Redux 工具包打字稿类型问题

Redux toolkit typescript type issue with next js and next-redux-wrapper

StackBlitz Demo

我按照 中下一个 js 的 redux 工具包设置。但是,原题的tsconfig.jsoncompilerOptions.strict = false,而我的是true。我遇到的问题在 store.js 中。如果您查看演示,在调用 configureStore 时,reducer 有以下问题:

Type '(state: ReturnType<typeof combinedReducer>, action: AnyAction) => any' is not assignable to type 'Reducer<CombinedState<{ counter: CounterState; kanyeQuote: KanyeState; }>, AnyAction> | ReducersMapObject<CombinedState<{ counter: CounterState; kanyeQuote: KanyeState; }>, AnyAction>'.

感谢任何帮助。

您可以将 reducer 定义更改为

const reducer: typeof combinedReducer = (state, action) => {

那就可以正常工作了。