Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better JSX types for form events #4098

Open
henribru opened this issue Jul 9, 2021 · 4 comments
Open

Better JSX types for form events #4098

henribru opened this issue Jul 9, 2021 · 4 comments
Labels
has workaround A workaround has been found to avoid the problem scope: types ✨ feature request New feature or request

Comments

@henribru
Copy link

henribru commented Jul 9, 2021

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

@posva posva added scope: types has workaround A workaround has been found to avoid the problem ✨ feature request New feature or request labels Jul 10, 2021
@pikax
Copy link
Member

pikax commented Jul 22, 2021

I was thinking we could have something similar to what React does #3370

@ctrlplusb
Copy link

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
Copy link
Contributor

kidonng commented Aug 28, 2022

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?

@kleinfreund
Copy link
Contributor

#9675 fixes the incorrect type definitions which seems to be the more immediately relevant fix. I'm running into this issue when assigning submit event listeners to form elements and using event: SubmitEvent in the listener's signature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has workaround A workaround has been found to avoid the problem scope: types ✨ feature request New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants