EventWithTarget<T, E>
ts
type EventWithTarget<T, E> = E & object;Allows setting the target property of a generic DOM event to a specific type of HTMLElement. Most of the time the typed EventTarget hinders to properly access the targetted element.
If the generics are not passed, the defaults are HTMLElement and Event.
Type Declaration
target
ts
target: T;Type Parameters
T
T extends HTMLElement = HTMLElement
E
E extends Event = Event
Example
ts
button.addEventListener('click', (event: EventWithTarget<HTMLButtonElement>) => {
event.target.disabled = true;
});