I am writing a simple component with Preact that uses an onChange
handler for an <input/>
element:
function Example(props: {}) {
return <input onChange={(e) => {
const { value } = e.currentTarget;
console.log(value);
}} />
}
The code above creates the following error:
Property 'value' does not exist on type 'EventTarget'.ts(2339)
The quickest fix would be to do a typecast:
const el = (e.currentTarget as HTMLInputElement).value;
but I do not want to add type casts to the application for such a common operation.
What is the correct way to write a form event handler without using typecasts or the any
type?
Environment Info:
"strict": true
in tsconfig.json[email protected]
- No external typings installed. Using package defaults.