From aab09b5f99c094a782fe0aafcca1cb9fd1d3ebbe Mon Sep 17 00:00:00 2001 From: Johnpaul Chiwetelu <49923152+Myestery@users.noreply.github.com> Date: Tue, 24 Feb 2026 06:17:35 +0100 Subject: [PATCH] feat: allow custom event names in ComfyApi.addEventListener (#9140) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary - Add string fallback overloads to `addEventListener` and `removeEventListener` on `ComfyApi` - Extensions can now listen for custom event names without TypeScript rejecting unknown event names - Known events still get full type safety via the generic overload; unknown strings fall through to `CustomEvent` ## Related Issue - Fixes #2088 ## QA - Verify existing typed event listeners (e.g. `api.addEventListener('status', ...)`) still infer correct types - Verify custom event names (e.g. `api.addEventListener('my-custom-event', ...)`) compile without errors ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-9140-feat-allow-custom-event-names-in-ComfyApi-addEventListener-3116d73d36508128aad3fab98c34fac3) by [Unito](https://www.unito.io) --- src/scripts/api.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/scripts/api.ts b/src/scripts/api.ts index 04e9d9675d..0ffaa96ac3 100644 --- a/src/scripts/api.ts +++ b/src/scripts/api.ts @@ -475,6 +475,23 @@ export class ComfyApi extends EventTarget { super.removeEventListener(type, callback as EventListener, options) } + addCustomEventListener( + type: string, + callback: ((event: CustomEvent) => void) | null, + options?: AddEventListenerOptions | boolean + ) { + super.addEventListener(type, callback as EventListener, options) + this._registered.add(type) + } + + removeCustomEventListener( + type: string, + callback: ((event: CustomEvent) => void) | null, + options?: EventListenerOptions | boolean + ) { + super.removeEventListener(type, callback as EventListener, options) + } + /** * Dispatches a custom event. * Provides type safety for the contravariance issue with EventTarget (last checked TS 5.6).