From 46a07f71e9664bf725cde40da1d0f27f6ddaf91d Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Mon, 8 Mar 2021 02:45:41 +0100 Subject: [PATCH] Improve type inference for the listener callback (#19) --- index.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/index.ts b/index.ts index 6de01a9..48b9aeb 100644 --- a/index.ts +++ b/index.ts @@ -83,12 +83,12 @@ function safeClosest(event: Event, selector: string): Element | void { */ function delegate< TElement extends Element = Element, - TEvent extends Event = Event + TEventType extends EventType = EventType >( base: EventTarget | Document | ArrayLike | string, selector: string, - type: EventType, - callback: delegate.EventHandler, + type: TEventType, + callback: delegate.EventHandler, options?: boolean | AddEventListenerOptions ): delegate.Subscription { // Handle Selector-based usage @@ -101,7 +101,7 @@ function delegate< const subscriptions = Array.prototype.map.call( base, (element: EventTarget) => { - return delegate( + return delegate( element, selector, type, @@ -127,7 +127,7 @@ function delegate< const delegateTarget = safeClosest(event, selector); if (delegateTarget) { (event as any).delegateTarget = delegateTarget; - callback.call(baseElement, event as delegate.Event); + callback.call(baseElement, event as delegate.Event); } };