【问题标题】:Redux toolkit + Typescript: extraReducersRedux 工具包 + Typescript:extraReducers
【发布时间】:2021-08-08 13:58:50
【问题描述】:

我正在尝试将 typescript 添加到我的 react/redux 项目中。 这是我的切片:

import { createSlice, createAsyncThunk, AnyAction, CaseReducer, PayloadAction } from '@reduxjs/toolkit';
export interface RequestStateBase {
    failed: boolean;
    executing: boolean;
    initialLoad: boolean;
    message: string | null;
    errors: any[]
}
const handlePending = (state: RequestStateBase) => {
    state.failed = false;
    state.executing = true;
    state.message = '';
}

const createCharacter = createAsyncThunk(
    'character/new',
    async (model: any) => characterClient.createCharacter(model)
);

const characterSlice = createSlice({
    name: "character",
    initialState: initialState,
    reducers: {
        cleanCharacterData: (state: CharacterState) => {
            //...
        },
        //...
    },
    extraReducers: builder => {
        builder.addCase(createCharacter.pending, handlePending),
        //...
    }
});

在 VS Code 中一切正常,但在构建过程中出现以下错误:

Line 78:9:  Expected an assignment or function call and instead saw an expression  @typescript-eslint/no-unused-expressions

第 78 行指的是builder.addCase(createCharacter.pending, handlePending)

如何解决?

【问题讨论】:

  • 请提供可重现的示例。我的意思是所有进口

标签: typescript redux redux-toolkit


【解决方案1】:

删除该行之后的, - 你可能想写;

逗号运算符在那里不会造成任何真正的伤害,但通常会导致意外行为 - 而且它似乎真的激怒了那里的 JSHint。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-08
    • 2020-05-29
    • 2021-01-05
    • 2021-11-28
    • 2021-06-03
    • 2021-06-24
    • 1970-01-01
    相关资源
    最近更新 更多