Skip to content

Commit

Permalink
Viewer: Add removeEventListener typings (#16155)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryantrem authored Feb 6, 2025
1 parent dbc3d4f commit 9878af0
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions packages/tools/viewer/src/viewerElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,25 @@ export interface ViewerElementEventMap extends HTMLElementEventMap {
selectedmaterialvariantchange: Event;
}

// eslint-disable-next-line jsdoc/require-jsdoc
export interface ViewerElement {
addEventListener<K extends keyof ViewerElementEventMap>(
type: K,
listener: (this: HTMLElement, ev: ViewerElementEventMap[K]) => any,
options?: boolean | AddEventListenerOptions
): void;

addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;

removeEventListener<K extends keyof ViewerElementEventMap>(
type: K,
listener: (this: HTMLElement, ev: ViewerElementEventMap[K]) => any,
options?: boolean | EventListenerOptions
): void;

removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
}

/**
* Base class for the viewer custom element.
*/
Expand Down Expand Up @@ -1033,16 +1052,6 @@ export abstract class ViewerElement<ViewerClass extends Viewer = Viewer> extends
`;
}

// eslint-disable-next-line babylonjs/available
override addEventListener<K extends keyof ViewerElementEventMap>(
type: K,
listener: (this: HTMLElement, ev: ViewerElementEventMap[K]) => any,
options?: boolean | AddEventListenerOptions
): void;
override addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void {
super.addEventListener(type as string, listener as EventListenerOrEventListenerObject, options as boolean | AddEventListenerOptions);
}

protected _dispatchCustomEvent<TEvent extends keyof ViewerElementEventMap>(type: TEvent, event: (type: TEvent) => ViewerElementEventMap[TEvent]) {
this.dispatchEvent(event(type));
}
Expand Down

0 comments on commit 9878af0

Please sign in to comment.