주로 나타나는 타입에러들을 정리해보니 대부분 기대한타입이 아닌 undefined일 경우의 에러다.
예외처리를 꼭 한 번 더 체크하자.
const stampImg = [...new Set(stampList.filter((item) => item.region === list).map((item) => item.stampimg))];
//Set 형식은 --downlevelIteration 플래그 또는 es2015 이상의 --target 을 사용하는 경우에만 반복할 수 있습니다.
tsconfig.json
"target": "es6",
"downlevelIteration": true, //이전 버전의 JS로 컴파일할 때, ES6 이상의 반복기능을 사용할 수 있도록(Set, Map, Array 사용가능)
if (!stampList) return console.log('데이터가 없습니다.'); //유효성 검사 추가(화면에는 안나오게 console 사용)
'StampList'은(는) JSX 구성 요소로 사용할 수 없습니다.
해당 '() => void | React.JSX.Element' 형식은 올바른 JSX 요소 형식이 아닙니다.
//BF
const region = decodeURIComponent(params.id);
//AF
const region = decodeURIComponent((params.id as string[]).toString());
//BF
const [stampData, setStampData] = useState<StampDetailPropsType | null>(null);
//AF
const [stampData, setStampData] = useState<StampDetailPropsType[]>([]); //null값 안받고, 기본값도 배열로 변경
{stampData.map((list) => (
<li key={list.id} className="flex items-center justify-between">
<p>{list.address}</p>
<span>{new Date(list.created_at).toLocaleDateString()}</span> //이 호출과 일치하는 오버로드가 없습니다.
</li>
))}
<span>{list.created_at ? new Date(list.created_at).toLocaleDateString() : 'N/A'}</span>
//BF
const oldestDate = stampData.reduce((oldest, current) => {
const oldestDate = new Date(oldest.created_at);
const currentDate = new Date(current.created_at);
return currentDate < oldestDate ? current : oldest;
}, stampData[0]);
//AF
const oldestDate = stampData.reduce((oldest, current) => {
const oldestDate = oldest.created_at ? new Date(oldest.created_at) : new Date();
const currentDate = current.created_at ? new Date(current.created_at) : new Date(); //있냐? > 있으면 앞에꺼 없으면 뒤에꺼
return currentDate < oldestDate ? current : oldest;
}, stampData[0]);
//BF
const stampFilterList = res?.filter((item) => item.region === decodedParams);
//AF
const stampFilterList = res?.filter((item) => item.region === decodedParams) || [];

import React, { useEffect, useState, Dispatch, SetStateAction } from 'react';
interface StampActivePropsType {
address: AddressPropsType;
setVisit: Dispatch<SetStateAction<Boolean>>;
visit: Boolean;
stampList: any[] | null | undefined; //TODO: any 추후수정
}