/** * Registry of known topic -> payload types. * * Consumers augment this interface via declaration merging so that * `pubSub.subscribe` / `pubSub.publish` enforce payload types per topic: * * ```ts * declare module '@changke/staticnext-lib' { * interface PubSubTopics { * 'user:login': {userId: string}; * } * } * ``` * * Topics not declared here fall back to `unknown`, preserving the legacy * untyped behavior. */ export interface PubSubTopics { [topic: string]: unknown; } type ListenerFn = (data: T) => void; interface Subscribed { remove: () => void; } /** * Simple event hub */ declare class PubSub { topics_: Map[]>; constructor(); subscribe(topic: K, listener: ListenerFn): Subscribed; publish(topic: K, data?: PubSubTopics[K]): void; subscribeOnce(topic: K, listener: ListenerFn): Subscribed; } declare const pubSub: PubSub; export default pubSub; export type { ListenerFn, Subscribed };