From 95e677edefd8421c2bd801e5b798dd8145e5e70e Mon Sep 17 00:00:00 2001 From: Simon Chan <1330321+yume-chan@users.noreply.github.com> Date: Sun, 29 Mar 2026 17:31:07 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20Merge=20PR=20#74769=20w3c-web-us?= =?UTF-8?q?b:=20allow=20strongly-typed=20event=20listeners=20to=20work=20w?= =?UTF-8?q?ith=20`AddEventListenerOptions`=20by=20@yume-chan?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Rob Moran --- types/w3c-web-usb/index.d.ts | 4 ++-- types/w3c-web-usb/w3c-web-usb-tests.ts | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/types/w3c-web-usb/index.d.ts b/types/w3c-web-usb/index.d.ts index e56e8aab9b2dfb..883fa94436f513 100644 --- a/types/w3c-web-usb/index.d.ts +++ b/types/w3c-web-usb/index.d.ts @@ -109,7 +109,7 @@ declare class USB extends EventTarget { addEventListener( type: "connect" | "disconnect", listener: (this: this, ev: USBConnectionEvent) => any, - useCapture?: boolean, + options?: boolean | AddEventListenerOptions, ): void; addEventListener( type: string, @@ -119,7 +119,7 @@ declare class USB extends EventTarget { removeEventListener( type: "connect" | "disconnect", callback: (this: this, ev: USBConnectionEvent) => any, - useCapture?: boolean, + options?: EventListenerOptions | boolean, ): void; removeEventListener( type: string, diff --git a/types/w3c-web-usb/w3c-web-usb-tests.ts b/types/w3c-web-usb/w3c-web-usb-tests.ts index b7d780927e490c..8c5e06da7ea22f 100644 --- a/types/w3c-web-usb/w3c-web-usb-tests.ts +++ b/types/w3c-web-usb/w3c-web-usb-tests.ts @@ -45,6 +45,16 @@ navigator.usb.addEventListener("connect", evt => { // Add |device| to the UI. handleConnectedDevice(evt.device); }); +// `options: boolean` +navigator.usb.addEventListener("connect", evt => { + // Add |device| to the UI. + handleConnectedDevice(evt.device); +}, true); +// `options: AddEventListenerOptions` +navigator.usb.addEventListener("connect", evt => { + // Add |device| to the UI. + handleConnectedDevice(evt.device); +}, { capture: true }); navigator.usb.addEventListener("disconnect", evt => { // Remove |device| from the UI.