admin 管理员组

文章数量: 1087652

【bug记录】 Argument of type ‘AsyncThunkAction<void, string, {}>‘ is not assignable to parameter of type

    const dispatch = useDispatch();   // 这里const dispatch: Dispatch<AnyAction>useEffect(() => {dispatch(getProductDetail(touristRouteId));}, []) 

getProductDetail的类型是 AsyncThunk<void, string, {}>,但是const dispatch: Dispatch<AnyAction>。 

export const getProductDetail=createAsyncThunk("productDetail/getProductDetail",async (touristRouteId:string, thunkAPI) => {const fetchData = async () => {thunkAPI.dispatch(productDetailSlice.actions.fetchStart());try {const { data } = await axios.get(`http://123.56.149.216:8080/api/touristRoutes/${touristRouteId}`);thunkAPI.dispatch(productDetailSlice.actions.fetchSuccess(data));} catch (error) {thunkAPI.dispatch(productDetailSlice.actions.fetchFail(error.message));}};fetchData();}
)

 两种解决办法:

一是定义getProductDetail是any类型

export const getProductDetail:any=createAsyncThunk("productDetail/getProductDetail",async (touristRouteId:string, thunkAPI) => {const fetchData = async () => {thunkAPI.dispatch(productDetailSlice.actions.fetchStart());try {const { data } = await axios.get(`http://123.56.149.216:8080/api/touristRoutes/${touristRouteId}`);thunkAPI.dispatch(productDetailSlice.actions.fetchSuccess(data));} catch (error) {thunkAPI.dispatch(productDetailSlice.actions.fetchFail(error.message));}};fetchData();}
)

二是用getDefaultMiddleware().concat而不是[...getDefaultMiddleware(),...]

const store = configureStore ({reducer:rootReducer,// 不要用展开运算符这种写法 middleware: (getDefaultMiddleware) => [...getDefaultMiddleware(), actionLog, changeLanguage],middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(actionLog,changeLanguage), devTools:true
});

本文标签:

Error[2]: Invalid argument supplied for foreach(), File: /www/wwwroot/roclinux.cn/tmp/view_template_quzhiwa_htm_read.htm, Line: 58
File: /www/wwwroot/roclinux.cn/tmp/route_read.php, Line: 205, include(/www/wwwroot/roclinux.cn/tmp/view_template_quzhiwa_htm_read.htm)
File: /www/wwwroot/roclinux.cn/tmp/index.inc.php, Line: 129, include(/www/wwwroot/roclinux.cn/tmp/route_read.php)
File: /www/wwwroot/roclinux.cn/index.php, Line: 29, include(/www/wwwroot/roclinux.cn/tmp/index.inc.php)