Skip to content

Commit

Permalink
nicer ordering of types
Browse files Browse the repository at this point in the history
  • Loading branch information
alexreardon committed May 5, 2022
1 parent a10a116 commit 5414144
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ type GetEventType<
? ExtractEventTypeFromHandler<Target[`on${EventName}`]>
: Event;

export type Binding<Target extends EventTarget = EventTarget, EventName extends string = string> = {
type: EventName;
listener: Listener<Target, EventName>;
options?: boolean | AddEventListenerOptions;
};

// For listener objects, the handleEvent function has the object as the `this` binding
type ListenerObject<TEvent extends Event> = {
handleEvent(this: ListenerObject<TEvent>, e: TEvent): void;
Expand All @@ -35,3 +29,9 @@ type ListenerObject<TEvent extends Event> = {
export type Listener<Target extends EventTarget, EventName extends string> =
| ListenerObject<GetEventType<Target, EventName>>
| { (this: Target, e: GetEventType<Target, EventName>): void };

export type Binding<Target extends EventTarget = EventTarget, EventName extends string = string> = {
type: EventName;
listener: Listener<Target, EventName>;
options?: boolean | AddEventListenerOptions;
};

0 comments on commit 5414144

Please sign in to comment.