Typescript: Which type for input's onChange event? #3390
-
This works with react, but not with preact:
I get So, which type can I use here? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 9 replies
-
After a lot of struggling the best I could come up was the code below.
For now it seems to me that preact plus Typescript is just broken. |
Beta Was this translation helpful? Give feedback.
-
Easiest way to type inputs is just: onInput={(e) => doSomething((e.target as HTMLInputElement).value)} Edit: If anyone has a better method, I'd love to see it done, but for now, as far as I'm aware, assertions (or ignore comments) are the way to go. |
Beta Was this translation helpful? Give feedback.
-
So what is right solution? |
Beta Was this translation helpful? Give feedback.
In newer Preact versions the event type is properly inferred, so the
JSX.TargetedEvent<HTMLInputElement, Event>
shouldn't be needed anymore.