Skip to content

Commit

Permalink
Improve type inference for the listener callback (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
stof authored Mar 8, 2021
1 parent c782d96 commit 46a07f7
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Element> | string,
selector: string,
type: EventType,
callback: delegate.EventHandler<TEvent, TElement>,
type: TEventType,
callback: delegate.EventHandler<GlobalEventHandlersEventMap[TEventType], TElement>,
options?: boolean | AddEventListenerOptions
): delegate.Subscription {
// Handle Selector-based usage
Expand All @@ -101,7 +101,7 @@ function delegate<
const subscriptions = Array.prototype.map.call(
base,
(element: EventTarget) => {
return delegate<TElement, TEvent>(
return delegate<TElement, TEventType>(
element,
selector,
type,
Expand All @@ -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<TEvent, TElement>);
callback.call(baseElement, event as delegate.Event<GlobalEventHandlersEventMap[TEventType], TElement>);
}
};

Expand Down

0 comments on commit 46a07f7

Please sign in to comment.