**我遇到的错误:**类型为'{ type:string; }'不能分配给类型为'{ type:string; } & void'.我正在使用redux thunk作为中间件,它工作正常6个月了,现在我试图重新安装它,它给了我这个错误。有人能调查一下吗
dispatch(getSummaryListingAction(GetSummaryListingsSuccess()));
dispatch(getSummaryListingAction(GetSummaryListingsError(e.message)));
dispatch(getSummaryListingAction(GetSummaryListingsError(e.message)));
dispatch(getSummaryListingAction(GetSummaryListingsError(e.message)));
编码
import { LossReportAxios } from "../../../services/axios";
import { getSummaryListingAction } from "../../slices/lossReportingSlice";
import { AppDispatch } from "../../store";
import { summaryListingActionTypes } from "../summaryListing/summaryListingActionTypes";
const GetSummaryListingsStart = () => ({
type: summaryListingActionTypes.GET_SUMMARYLISTING_START
});
const GetSummaryListingsSuccess = () => ({
type: summaryListingActionTypes.GET_SUMMARYLISTING_SUCCESS,
});
const GetSummaryListingsError = (payload: any) => ({
type: summaryListingActionTypes.GET_SUMMARYLISTING_ERROR,
payload: payload
});
export const GetSummaryListings = (token: string,searchObjParams:any,searchBy:string,gridparams:any,navigate:any) => {
return (dispatch: AppDispatch) => {
dispatch(getSummaryListingAction(GetSummaryListingsStart()));
if(searchBy === "CLIENT"){
LossReportAxios
.post(
"/SummaryListingLossesByDepartmentForClientId",
searchObjParams,
{
headers: {
Authorization: `Bearer ${token}`,
},
}
).then(function (res:any) {
var totalRows = -1;
if (res.data !== null && res.data !== undefined) {
if (res.data.length < 10) {
totalRows = gridparams.request.startRow + res.data.length;
}
gridparams.successCallback(res.data, totalRows);
dispatch(getSummaryListingAction(GetSummaryListingsSuccess()));
} else {
gridparams.successCallback([], totalRows);
}
}).catch((e:any) => {
dispatch(getSummaryListingAction(GetSummaryListingsError(e.message)));
});
} else {
LossReportAxios
.post(
"/SummaryListingLossesByDepartmentForPolicyId",
searchObjParams,
{
headers: {
Authorization: `Bearer ${token}`,
},
}
).then(function (res:any) {
var totalRows = -1;
if (res.data) {
if (res.data.length < 50) {
totalRows = gridparams.request.startRow + res.data.length;
}
gridparams.successCallback(res.data, totalRows);
dispatch(getSummaryListingAction(GetSummaryListingsSuccess()));
} else {
gridparams.successCallback([], totalRows);
}
}).catch((e:any) => {
dispatch(getSummaryListingAction(GetSummaryListingsError(e.message)));
});
}
}
}
精简配置
import { configureStore } from '@reduxjs/toolkit'
import { persistedReducer } from './RootReducer';
import logger from "redux-logger";
import thunk from 'redux-thunk';
export const store = configureStore({
reducer: persistedReducer
})
export const storeWithLogger = configureStore({
reducer: persistedReducer,
middleware:(gDM) => gDM({
serializableCheck:false
}).concat(logger,thunk)
})
export type RootState = ReturnType<typeof store.getState>
export type AppDispatch = typeof store.dispatch
2条答案
按热度按时间w8biq8rn1#
对于测试,请忽略
concat
中的thunk
中间件-Redux形实转换中间件已经是getDefaultMiddlware
的一部分。如果这没有帮助:你能附上你在悬停
AppDispatch
类型时得到的确切类型吗?llew8vvj2#
解决了!这似乎wierd,但解决方案如下:
以前我用的是action:any