Skip to content

Commit 087a0e7

Browse files
committed
Add add/removeEventListener overloads from HTMLElement
WebviewTag adds electron-specific overloads to addEventListener and removeEventListener when it extends HTMLElement. However, it does not include the original overloads from HTMLElement, and Typescript does not include them when WebviewTag extends HTMLElement. This change adds those previously-missed overloads to WebviewTag. It is necessary to allow users of electron.d.ts to compile with Typescript 2.6 --strict.
1 parent cb892a8 commit 087a0e7

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

lib/module-declaration.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ const generateModuleDeclaration = (module, index, API) => {
105105
moduleAPI.push(`${method}(event: '${domEvent.name}', listener: (event: ${eventType}) => void${method === 'addEventListener' ? ', useCapture?: boolean' : ''}): this;`)
106106
}
107107
})
108+
109+
// original overloads copied from HTMLElement, because they are not inherited
110+
moduleAPI.push(`addEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any, useCapture?: boolean): void;`)
111+
moduleAPI.push(`addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void;`)
112+
moduleAPI.push(`removeEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any, useCapture?: boolean): void;`)
113+
moduleAPI.push(`removeEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void;`)
108114
}
109115

110116
const returnsThis = (moduleMethod) => ['on', 'once', 'removeAllListeners', 'removeListener'].includes(moduleMethod.name)

0 commit comments

Comments
 (0)