From 3129b4c200b79373bb602c0f1a1386e595dbe97d Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Fri, 8 Oct 2021 17:26:58 -0700 Subject: [PATCH] fix: correct types for addEventListener, removeEventListener Signed-off-by: Anders Kaseorg --- src/module-declaration.ts | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/module-declaration.ts b/src/module-declaration.ts index 3433865..9d3ff59 100644 --- a/src/module-declaration.ts +++ b/src/module-declaration.ts @@ -189,27 +189,34 @@ export const generateModuleDeclaration = ( ); } - for (let method of ['addEventListener', 'removeEventListener']) { - moduleAPI.push( - `${method}(event: '${domEvent.name}', listener: (event: ${eventType}) => void${ - method === 'addEventListener' ? ', useCapture?: boolean' : '' - }): this;`, - ); - } + moduleAPI.push( + `addEventListener(event: '${domEvent.name}', listener: (this: ${_.upperFirst( + module.name, + )}, event: ${eventType}) => void, options?: boolean | AddEventListenerOptions): void;`, + ); + moduleAPI.push( + `removeEventListener(event: '${domEvent.name}', listener: (this: ${_.upperFirst( + module.name, + )}, event: ${eventType}) => void, options?: boolean | EventListenerOptions): void;`, + ); }); // original overloads copied from HTMLElement, because they are not inherited moduleAPI.push( - `addEventListener(type: K, listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any, useCapture?: boolean): void;`, + `addEventListener(type: K, listener: (this: ${_.upperFirst( + module.name, + )}, ev: HTMLElementEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;`, ); moduleAPI.push( - `addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void;`, + `addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;`, ); moduleAPI.push( - `removeEventListener(type: K, listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any, useCapture?: boolean): void;`, + `removeEventListener(type: K, listener: (this: ${_.upperFirst( + module.name, + )}, ev: HTMLElementEventMap[K]) => any, options?: boolean | EventListenerOptions): void;`, ); moduleAPI.push( - `removeEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void;`, + `removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;`, ); } }