Below is the form I currently have:
<form id="search" method="post">
<input type="text" name="query" id="search-field"/>
</form>
I am looking to add a submit event listener in TypeScript:
document.getElementById("search").addEventListener("submit", (event: SubmitEvent) => {
event.preventDefault();
console.log(event.target.children.query.value);
});
However, TypeScript is throwing an error:
error TS2339: Property 'children' does not exist on type 'EventTarget'.
20 console.log(event.target.children.query.value);
Is there a way to let TypeScript know that the target of the submit event is a form with a valid children.query
element?