onSubmit에서 input 값을 보고 싶은데... 타입스크립트에서 오류가 난다.
onSubmit={(e) => {
e.preventDefault();
const topic = e.currentTarget.topic;
const content = e.currentTarget.content;
function assertIsFormFieldElement(
element: Element | HTMLSelectElement | HTMLButtonElement,
): asserts element is HTMLInputElement {
if (!('value' in element)) throw new Error('폼 요소가 아님');
}
assertIsFormFieldElement(topic);
console.log("values ==== ", topic.value, content);
}}
해결안은 assert 함수를 만들어서 해당 오브젝트에 value 프로퍼티가 있는지 체크한다.
이런 유용한 정보를 나눠주셔서 감사합니다.