The Vue documentation has this section: Typing Event Handlers.
Their recommendation is (not too satisfying) to use the generic Event type, and type assert properties as needed:
handleChange( event: Event ){
console.log( (event.target as HTMLInputElement).value );
}
I don't see a really better solution for now.
Future ?
The HTMLElement change event (which you are using on the HTMLInputElement in your example) is indeed just a generic Event.
In other cases it would be desirable to use a more specific event, e.g. the click event is of the type PointerEvent, but it seems that only Event is defined right now for all events, so we have to deal with it.
Also specifying the target elements type would be nice (with "Generics"), like:
function handler( event: PointerEvent<HTMLInputElement> ){} // <-- doesn't work yet
But the specific elements type seems not to be available at this point. Maybe this will be supported in some future version of Vue (?).
Notes about not working solutions
One may try to define own types (I tried that myself), like:
interface MyPointerEvent<T extends EventTarget> {
target: T;
}
const handleClick = function(event: MyPointerEvent<HTMLTableCellElement>){
// ...
};
This gives you auto completion and correct typing inside the function, but this would still cause an error in Vue templates:
<template>
<button @click=handleClick></button>
// ^-- Error: `onClick: ( event: MyPointerEvent<HTMLTableCellElement> ) => void;`
// is not assignable to `ButtonHTMLAttributes & ReservedProps & Record<string, unknown>`
</template>