@augment-vir/web
Version:
A collection of augments, helpers types, functions, and classes only for web (frontend) JavaScript environments.
27 lines (26 loc) • 1.19 kB
TypeScript
import { type PartialWithUndefined } from '@augment-vir/common';
import { type AbstractConstructor, type Constructor } from 'type-fest';
/**
* Extract the event target element from an Event.
*
* @category Web : Elements
* @category Package : @augment-vir/web
* @example
*
* ```ts
* element.addEventListener('click', (event) => {
* const eventTarget = extractEventTarget(event, HTMLButtonElement);
* });
* ```
*
* @package [`@augment-vir/web`](https://www.npmjs.com/package/@augment-vir/web)
*/
export declare function extractEventTarget<ExpectedTargetClassConstructor extends AbstractConstructor<Element> | Constructor<Element>>(event: Event, expectedTargetClass: ExpectedTargetClassConstructor, options?: PartialWithUndefined<{
/**
* By default `extractEventTarget` uses the `Event.currentTarget` field to extract the event
* target so that it extract the target to which the event handler was attached to. However,
* if you wish to instead use the `Event.target` property, to extract the element which
* originally fired the event, set this to true.
*/
useOriginalTarget: boolean;
}>): InstanceType<ExpectedTargetClassConstructor>;