【问题标题】:Redux toolkit typescript type issue with next js and next-redux-wrapperNext js 和 next-redux-wrapper 的 Redux 工具包 typescript 类型问题
【发布时间】:2022-01-09 06:10:06
【问题描述】:

StackBlitz Demo

我按照 here 中为 next js 设置的 redux 工具包。但是,在原始问题的tsconfig.jsoncompilerOptions.strict = false 中,我的是true。我遇到的问题是store.js。如果你看demo,在调用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>'.

感谢任何帮助。

【问题讨论】:

    标签: reactjs typescript next.js redux-toolkit


    【解决方案1】:

    您可以将reducer 定义更改为

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

    那么它就可以正常工作了。

    【讨论】:

    • 我刚刚做了,但仍然出现一些类型错误Type '(state: ReturnType&lt;typeof combinedReducer&gt;, action: AnyAction) =&gt; any' is not assignable to type 'Reducer&lt;CombinedState&lt;{ counter: CounterState; kanyeQuote: KanyeState; }&gt;, AnyAction&gt;'.我在同一个 stackblitz 演示链接中应用了更改。
    • 是的,因为您向stateaction 添加了我明确删除的类型。
    猜你喜欢
    • 2021-01-16
    • 2018-06-04
    • 2022-01-22
    • 2021-10-05
    • 2021-11-18
    • 2022-01-26
    • 1970-01-01
    • 2021-11-06
    • 2019-11-10
    相关资源
    最近更新 更多