aboutsummaryrefslogtreecommitdiffstats
path: root/svg.js.d.ts
diff options
context:
space:
mode:
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2024-07-16 15:57:35 +0200
committerUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2024-07-16 15:57:35 +0200
commitb83e507ddab4af1a9f0d5dc01009d03a63a8fbdc (patch)
treea5d5f8457da32351af88b5806f5e10927044a0c5 /svg.js.d.ts
parentec9d2fc952a683aaa9f0c523fbba0786babdf629 (diff)
downloadsvg.js-b83e507ddab4af1a9f0d5dc01009d03a63a8fbdc.tar.gz
svg.js-b83e507ddab4af1a9f0d5dc01009d03a63a8fbdc.zip
fix(types): make on/off genericmake-on-off-generic
Diffstat (limited to 'svg.js.d.ts')
-rw-r--r--svg.js.d.ts58
1 files changed, 36 insertions, 22 deletions
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<K extends keyof SVGDotJsEventMap, El extends Node | Window>(
+ 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 extends Node | Window>(
+ 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<K extends keyof SVGDotJsEventMap, El extends Node | Window>(
+ 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 extends Node | Window>(
+ 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<K extends keyof SVGDotJsEventMap>(
+ 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<K extends keyof SVGDotJsEventMap>(
+ 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