ryansolid / babel-plugin-jsx-dom-expressions

A JSX to DOM plugin that wraps expressions for fine grained change detection
MIT License
60 stars 10 forks source link

Add support for Event.target. #20

Closed rbiggs closed 5 years ago

rbiggs commented 5 years ago
  1. Previously using Event.target.value with and input resulted in a warning that EventTarget did not have property value. EventTarget was not recongizing that it was an HTMLInputElement. Adding target to the EventHandler forces TypeScript to recognize that target of event on HTMLInputElement has a property "value".
rbiggs commented 5 years ago

I was registering an oninput event in my JSX on an input tag. Then in the handler I was capturing the value of the input like so:

<input onclick={e => send(e.target.value)} type='text'/>

But in Visual Studio Code I was getting red squiggles warning me the the property "value" did not exist on EventTarget. This change makes target point to the element the event is registered on. So, in the case of an input of type text or a textarea, e.target.value is valid and it knows that value is of type string.

ryansolid commented 5 years ago

Ok strange, you would have thought it was there. Hmm.. I wonder if typing the way I've been for Events are just wrong since the native events would just be fine. In any case this is common enough I will just merge as is for now.

Thank you.