vuejs / core

🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
https://vuejs.org/
MIT License
47.61k stars 8.32k forks source link

Better JSX types for form events #4098

Open henribru opened 3 years ago

henribru commented 3 years ago

What problem does this feature solve?

Currently the JSX types specify that native input event handlers receive an Event: https://github.com/vuejs/vue-next/blob/8ed3ed6c27b0fb9a1b6994eddc967e42d4b3d4e1/packages/runtime-dom/types/jsx.d.ts#L1210

This is very general compared to the runtime type. As an example, @input on an input element will actually give you an InputEvent. It would be useful if the correct event type could be inferred so that we don't have to cast the event object. I assume it's not as simple as e.g. replacing Event with InputEvent for onInput or it would probably have been done already, but is this something that could potentially be solved?

What does the proposed API look like?

N/A, just a type improvement, not an API

pikax commented 3 years ago

I was thinking we could have something similar to what React does https://github.com/vuejs/vue-next/pull/3370

ctrlplusb commented 3 years ago

Would love this. I have had to write a utility to narrow the event types at the moment but would prefer to avoid the additional boilerplate.

kidonng commented 2 years ago

I assume it's not as simple as e.g. replacing Event with InputEvent for onInput or it would probably have been done already

Would like an explanation why they are typed as such. They are only used for JSX so I don't think it would actually break anything.

@pikax kindly asking what's blocking #3370? If that PR could not be landed in the near future, could we at least have these types corrected (e.g. onInput: InputEvent) first?