Skip to content

Commit 3129b4c

Browse files
committed
fix: correct types for addEventListener, removeEventListener
Signed-off-by: Anders Kaseorg <[email protected]>
1 parent 222f7be commit 3129b4c

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

Diff for: src/module-declaration.ts

+18-11
Original file line numberDiff line numberDiff line change
@@ -189,27 +189,34 @@ export const generateModuleDeclaration = (
189189
);
190190
}
191191

192-
for (let method of ['addEventListener', 'removeEventListener']) {
193-
moduleAPI.push(
194-
`${method}(event: '${domEvent.name}', listener: (event: ${eventType}) => void${
195-
method === 'addEventListener' ? ', useCapture?: boolean' : ''
196-
}): this;`,
197-
);
198-
}
192+
moduleAPI.push(
193+
`addEventListener(event: '${domEvent.name}', listener: (this: ${_.upperFirst(
194+
module.name,
195+
)}, event: ${eventType}) => void, options?: boolean | AddEventListenerOptions): void;`,
196+
);
197+
moduleAPI.push(
198+
`removeEventListener(event: '${domEvent.name}', listener: (this: ${_.upperFirst(
199+
module.name,
200+
)}, event: ${eventType}) => void, options?: boolean | EventListenerOptions): void;`,
201+
);
199202
});
200203

201204
// original overloads copied from HTMLElement, because they are not inherited
202205
moduleAPI.push(
203-
`addEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any, useCapture?: boolean): void;`,
206+
`addEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: ${_.upperFirst(
207+
module.name,
208+
)}, ev: HTMLElementEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;`,
204209
);
205210
moduleAPI.push(
206-
`addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void;`,
211+
`addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;`,
207212
);
208213
moduleAPI.push(
209-
`removeEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any, useCapture?: boolean): void;`,
214+
`removeEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: ${_.upperFirst(
215+
module.name,
216+
)}, ev: HTMLElementEventMap[K]) => any, options?: boolean | EventListenerOptions): void;`,
210217
);
211218
moduleAPI.push(
212-
`removeEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void;`,
219+
`removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;`,
213220
);
214221
}
215222
}

0 commit comments

Comments
 (0)