Skip to content

Commit 9da5ea8

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

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

Diff for: src/module-declaration.ts

+10-11
Original file line numberDiff line numberDiff line change
@@ -189,27 +189,26 @@ 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: (event: ${eventType}) => void, options?: boolean | AddEventListenerOptions): void;`,
194+
);
195+
moduleAPI.push(
196+
`removeEventListener(event: '${domEvent.name}', listener: (event: ${eventType}) => void, options?: boolean | EventListenerOptions): void;`,
197+
);
199198
});
200199

201200
// original overloads copied from HTMLElement, because they are not inherited
202201
moduleAPI.push(
203-
`addEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any, useCapture?: boolean): void;`,
202+
`addEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;`,
204203
);
205204
moduleAPI.push(
206-
`addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void;`,
205+
`addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;`,
207206
);
208207
moduleAPI.push(
209-
`removeEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any, useCapture?: boolean): void;`,
208+
`removeEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | EventListenerOptions): void;`,
210209
);
211210
moduleAPI.push(
212-
`removeEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void;`,
211+
`removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;`,
213212
);
214213
}
215214
}

0 commit comments

Comments
 (0)