hono
hono copied to clipboard
Types for Events
What is the feature you are proposing?
We want to have React-like TypeScript types for HTML events like a React.ChangeEvent.
For example, the simple one could be implemented as the following:
interface ChangeEvent<T = Element> {
target: EventTarget & T
}
const Input = (
<input
type="checkbox"
onChange={(e: ChangeEvent<HTMLInputElement>) => setFoo(e.target.checked)}
/>
)
There are some event types other than React.ChangeEvent:
type Props = {
onClick: (event: React.MouseEvent<HTMLInputElement>) => void
onChange: (event: React.ChangeEvent<HTMLInputElement>) => void
onKeypress: (event: React.KeyboardEvent<HTMLInputElement>) => void
onBlur: (event: React.FocusEvent<HTMLInputElement>) => void
onFocus: (event: React.FocusEvent<HTMLInputElement>) => void
onSubmit: (event: React.FormEvent<HTMLFormElement>) => void
onClickDiv: (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => void
}
It will be tough but, maybe we can do it.
Fixed!