From: Ulrich-Matthias Schäfer Date: Tue, 16 Jul 2024 13:57:35 +0000 (+0200) Subject: fix(types): make on/off generic X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fheads%2Fmake-on-off-generic;p=svg.js.git fix(types): make on/off generic --- diff --git a/svg.js.d.ts b/svg.js.d.ts index 5fd0513..f337c7c 100644 --- a/svg.js.d.ts +++ b/svg.js.d.ts @@ -16,6 +16,8 @@ interface CSSStyleDeclarationWithVars extends CSSStyleDeclaration { } declare module '@svgdotjs/svg.js' { + export interface SVGDotJsEventMap extends HTMLElementEventMap {} + function SVG(): Svg /** * @param selectorOrHtml pass in a css selector or an html/svg string @@ -35,31 +37,32 @@ declare module '@svgdotjs/svg.js' { function prepare(element: HTMLElement): void function getClass(name: string): Element - function on( - el: Node | Window, - events: string, - cb: EventListener, - binbind?: any, + function on( + el: El, + event: K, + cb: (this: El, ev: SVGDotJsEventMap[K]) => any, options?: AddEventListenerOptions - ): void - function on( - el: Node | Window, - events: Event[], - cb: EventListener, + ): void; + + function on( + el: El, + events: string | string[], + cb: (this: El, ev: Event) => any, binbind?: any, options?: AddEventListenerOptions ): void - function off( - el: Node | Window, - events?: string, - cb?: EventListener | number, + function off( + el: El, + events?: K, + cb?: (this: El, ev: SVGDotJsEventMap[K]) => any, options?: AddEventListenerOptions ): void - function off( - el: Node | Window, - events?: Event[], - cb?: EventListener | number, + + function off( + el: El, + events?: string | string[], + cb?: (this: El, ev: any) => any, options?: AddEventListenerOptions ): void @@ -692,15 +695,26 @@ declare module '@svgdotjs/svg.js' { getEventHolder(): this | Node getEventTarget(): this | Node + on( + events: K, + cb: (ev: SVGDotJsEventMap[K]) => any, + binbind?: any, + options?: AddEventListenerOptions + ): this on( - events: string | Event[], - cb: EventListener, + events: string | string[], + cb: (ev: Event) => any, binbind?: any, options?: AddEventListenerOptions ): this + off( + events?: K, + cb?: (ev: any) => any, + options?: AddEventListenerOptions + ): this off( - events?: string | Event[], - cb?: EventListener | number, + events?: string | string[], + cb?: (ev: any) => any, options?: AddEventListenerOptions ): this