【发布时间】: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