我开始在我设置过的地方设置特定类型。编译时,出现如下错误:
const dispatch = useAppDispatch();
const showModalConstructor = (item: TypePizzaItem) => {
dispatch(openModalItemConstructor(item));
return;
}
行动:
export const openModalItemConstructor = createAction('OPEN_MODAL_ITEM');
类型:
export type TypePizzaItem = {
id: number,
title: string,
description: string,
price: number,
img: {
traditional: {
medium: string,
big: string
}
},
volume: string | null,
volumes?: {
traditional: string[],
thin: string[]
},
quantity?: number,
}
使用文档中描述的钩子检索调度:
import { TypedUseSelectorHook, useDispatch, useSelector } from 'react-redux'
import type { RootState, AppDispatch } from '../store/store'
// Используйте во всем приложении вместо обычных `useDispatch` и `useSelector`
type DispatchFunc = () => AppDispatch
export const useAppDispatch: DispatchFunc = useDispatch
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector
我不明白为什么会出现这个问题以及代码中需要更改什么?