diff --git a/packages/design-system/src/utils/event-bus.ts b/packages/design-system/src/utils/event-bus.ts index 23f5e5f02acf8e..1b7cb10182a48c 100644 --- a/packages/design-system/src/utils/event-bus.ts +++ b/packages/design-system/src/utils/event-bus.ts @@ -2,17 +2,51 @@ export type CallbackFn = Function; export type UnregisterFn = () => void; -export interface EventBus { - on: (eventName: string, fn: CallbackFn) => UnregisterFn; - once: (eventName: string, fn: CallbackFn) => UnregisterFn; - off: (eventName: string, fn: CallbackFn) => void; - emit: (eventName: string, event?: T) => void; +export type Listener = (payload: Payload) => void; + +export type Payloads = { + [E in keyof ListenerMap]: unknown; +}; + +// TODO: Fix all usages of `createEventBus` and convert `any` to `unknown` +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export interface EventBus = Record> { + on: ( + eventName: EventName, + fn: Listener, + ) => UnregisterFn; + + once: ( + eventName: EventName, + fn: Listener, + ) => UnregisterFn; + + off: ( + eventName: EventName, + fn: Listener, + ) => void; + + emit: ( + eventName: EventName, + event?: ListenerMap[EventName], + ) => void; } /** - * @deprecated Use the typed version instead from `typed-event-bus.ts` + * Creates an event bus with the given listener map. + * + * @example + * ```ts + * const eventBus = createEventBus<{ + * 'user-logged-in': { username: string }; + * 'user-logged-out': never; + * }>(); */ -export function createEventBus(): EventBus { +export function createEventBus< + // TODO: Fix all usages of `createEventBus` and convert `any` to `unknown` + // eslint-disable-next-line @typescript-eslint/no-explicit-any + ListenerMap extends Payloads = Record, +>(): EventBus { const handlers = new Map(); function off(eventName: string, fn: CallbackFn) { diff --git a/packages/design-system/src/utils/typed-event-bus.ts b/packages/design-system/src/utils/typed-event-bus.ts deleted file mode 100644 index 8290b68fb2a8a2..00000000000000 --- a/packages/design-system/src/utils/typed-event-bus.ts +++ /dev/null @@ -1,36 +0,0 @@ -import type { UnregisterFn } from './event-bus'; -import { createEventBus as createUntypedEventBus } from './event-bus'; - -export type Listener = (payload: Payload) => void; - -export type Payloads = { - [E in keyof ListenerMap]: unknown; -}; - -export interface TypedEventBus> { - on: ( - eventName: EventName, - fn: Listener, - ) => UnregisterFn; - - once: ( - eventName: EventName, - fn: Listener, - ) => UnregisterFn; - - off: ( - eventName: EventName, - fn: Listener, - ) => void; - - emit: ( - eventName: EventName, - event?: ListenerMap[EventName], - ) => void; -} - -export function createTypedEventBus< - ListenerMap extends Payloads, ->(): TypedEventBus { - return createUntypedEventBus() as TypedEventBus; -} diff --git a/packages/editor-ui/src/components/Modal.vue b/packages/editor-ui/src/components/Modal.vue index 7f4a8334af6fad..141e93a521472a 100644 --- a/packages/editor-ui/src/components/Modal.vue +++ b/packages/editor-ui/src/components/Modal.vue @@ -1,7 +1,7 @@