EventWithRelatedTarget<T, E>
ts
type EventWithRelatedTarget<T, E> = E & object;Allows setting the relatedTarget property of a generic DOM event to a specific type of HTMLElement. This is useful for events like focus, blur, or pointerover where you want to access the related element.
If the generics are not passed, the defaults are HTMLElement and Event.
Type Declaration
relatedTarget
ts
relatedTarget: T;Type Parameters
T
T extends HTMLElement = HTMLElement
E
E extends Event = Event
Example
ts
form.addEventListener('focus', (event: EventWithRelatedTarget<HTMLInputElement>) => {
console.log(event.relatedTarget); // Access the related target element
});