setAllConcerts: (state: main, { payload }: PayloadAction<???>) => {
state.allConcerts = payload;
},
타입부분에 <Array>
라고 적으면 Generic type 'Array<T>'
requires 1 type argument(s)라는 2314번 에러가 나온다. any든 뭐든 인자를 하나 적어주어야 한다는 것같다.
타입부분에 <Array<any>>
또는 <Array<object>
라고 쓰면
'Type 'object[]'is not assignable to type'[]'이라고 2322번 에러가 나온다.
뭔가 이상하다 싶어서 보니 interface main으로 state type을 설정해줄 때 []
(any도 안적힌 그냥 array)라고 작성했어서 interface부분과 reducer부분의 type이 안맞아서 일어난 에러였다.
/* object props 받기*/
type concertProps = { concert: object }
function ConcertBox(concert: concertProps ) {
return (
....(중략)...
/* 함수 props 받기 */
type MyProps = {
handleEdit: () => void;
}
function MyProfileImageModal({ handleEdit}: MyProps) {
/* object props 받기*/
interface Props {
concert: object
}
function ConcertBox({concert} : Props ) {
return (
....(중략)...
props를 전달해주는 부모 컴포넌트 쪽은 보내는 과정이 똑같다. 다만 받는쪽(자식 컴포넌트)에서 타입을 설정해주어야 한다.