Types
Bridge
Section titled “Bridge”The main bridge interface returned by createBridge() and exported as the bridge singleton.
interface Bridge { postMessage(type: string, payload?: unknown): void onMessage(handler: MessageHandler): () => void}MessageHandler
Section titled “MessageHandler”The callback type passed to bridge.onMessage.
type MessageHandler = (message: unknown) => voidTyping your messages
Section titled “Typing your messages”Since messages are typed as unknown by default, it’s recommended to narrow the type in your handler. A common pattern is to use a discriminated union:
interface OpenFileMessage { type: 'openFile' payload: { path: string }}
interface NotificationMessage { type: 'notification' payload: { text: string; level: 'info' | 'warning' | 'error' }}
type IDEMessage = OpenFileMessage | NotificationMessage
bridge.onMessage((raw) => { const msg = raw as IDEMessage if (msg.type === 'openFile') { console.log('Open:', msg.payload.path) }})