最新消息: USBMI致力于为网友们分享Windows、安卓、IOS等主流手机系统相关的资讯以及评测、同时提供相关教程、应用、软件下载等服务。

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

IT圈 admin 13浏览 0评论

【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
});

【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
});

TypeError: array_keys(): Argument #1 ($array) must be of type array, null given in /www/wwwroot/www.usbmi.com/tmp/view_template_d8_htm_read.htm:240 Stack trace: #0 /www/wwwroot/www.usbmi.com/tmp/view_template_d8_htm_read.htm(240): array_keys() #1 /www/wwwroot/www.usbmi.com/tmp/route_read.php(204): include('...') #2 /www/wwwroot/www.usbmi.com/tmp/index.inc.php(129): include('...') #3 /www/wwwroot/www.usbmi.com/index.php(29): include('...') #4 {main}