Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(types): make on/off generic #1320

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 36 additions & 22 deletions svg.js.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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

Expand Down