Skip to content

Commit 95e677e

Browse files
yume-chanthegecko
andauthored
🤖 Merge PR DefinitelyTyped#74769 w3c-web-usb: allow strongly-typed event listeners to work with AddEventListenerOptions by @yume-chan
Co-authored-by: Rob Moran <github@thegecko.org>
1 parent c688f9c commit 95e677e

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

‎types/w3c-web-usb/index.d.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ declare class USB extends EventTarget {
109109
addEventListener(
110110
type: "connect" | "disconnect",
111111
listener: (this: this, ev: USBConnectionEvent) => any,
112-
useCapture?: boolean,
112+
options?: boolean | AddEventListenerOptions,
113113
): void;
114114
addEventListener(
115115
type: string,
@@ -119,7 +119,7 @@ declare class USB extends EventTarget {
119119
removeEventListener(
120120
type: "connect" | "disconnect",
121121
callback: (this: this, ev: USBConnectionEvent) => any,
122-
useCapture?: boolean,
122+
options?: EventListenerOptions | boolean,
123123
): void;
124124
removeEventListener(
125125
type: string,

‎types/w3c-web-usb/w3c-web-usb-tests.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ navigator.usb.addEventListener("connect", evt => {
4545
// Add |device| to the UI.
4646
handleConnectedDevice(evt.device);
4747
});
48+
// `options: boolean`
49+
navigator.usb.addEventListener("connect", evt => {
50+
// Add |device| to the UI.
51+
handleConnectedDevice(evt.device);
52+
}, true);
53+
// `options: AddEventListenerOptions`
54+
navigator.usb.addEventListener("connect", evt => {
55+
// Add |device| to the UI.
56+
handleConnectedDevice(evt.device);
57+
}, { capture: true });
4858

4959
navigator.usb.addEventListener("disconnect", evt => {
5060
// Remove |device| from the UI.

0 commit comments

Comments
 (0)