'How to type SubmitEvent so that event.target.children is known?
I have the following form:
<form id="search" method="post">
<input type="text" name="query" id="search-field"/>
</form>
And I want to attach a submit event listener in TypeScript:
document.getElementById("search").addEventListener("submit", (event: SubmitEvent) => {
event.preventDefault();
console.log(event.target.children.query.value);
});
However typescript gives me the following error:
error TS2339: Property 'children' does not exist on type 'EventTarget'.
20 console.log(event.target.children.query.value);
How can I tell TypeScript that the target of the submit event is a form, which has a valid children.query element?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
