core
core copied to clipboard
types: Add type helpers for DOM event handling
Adding type helpers to easy the transition from React to Vue.
Motivation
People coming from React are used to have this type helpers to type DOM events, which in Vue we don't have anything similar out-of-the box and expect users to understand how to type it with typescript is not ideal.
Implementation
I just copied the current types from React, only the SyntheticEvent is not copied because itself already extends the Event from dom.
Usage
import { InputEvent } from 'vue'
function onInput(ev: InputEvent<HTMLInputElement>) {
const text = ev.target.value; // string
}
Possible problems
Because is using the same name as the native Events, it might confuse some users (because it requires to input from 'vue').