Date 형식을 입맛대로 변경하는 과정에서 DateTimeFormatOption
을 전달할 때 타입오류 발생
const formatTimestamp = (timestamp: string) => {
const options = {
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
hour12: true,
};
const date = new Date(timestamp);
// options 인자에서 타입오류 발생
const formattedDate = date.toLocaleString("ko-KO", options);
return formattedDate;
};
const options: Intl.DateTimeFormatOptions = {
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
hour12: true,
};
위와같은 타입이 선언되어야 date.toLocaleString()
의 두번째 인자로 전달될 때 타입오류가 나지 않음