gpt4 book ai didi

typescript - Redux 工具包 + typescript : extraReducers

转载 作者:行者123 更新时间:2023-12-05 08:46:55 25 4
gpt4 key购买 nike

我正在尝试将 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)

如何解决?

最佳答案

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

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

关于typescript - Redux 工具包 + typescript : extraReducers,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68701473/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com