## Handler Types in Output Interfaces Handlers exposed in Output interfaces must be typed as `Stream`. ```typescript import { Stream } from 'commontools'; interface Output { count: number; increment: Stream; // Handler with no parameters setCount: Stream<{ value: number }>; // Handler with parameters } ``` **Why Stream?** - `Stream` represents a write-only channel for triggering actions - Other pieces can call these handlers via `.send()` when linked ### Creating Streams (Bound Handlers) A bound handler IS a `Stream`. Don't try to create streams directly: ```typescript import { handler, pattern, Writable, Stream } from 'commontools'; interface Item { title: string } // ✅ CORRECT - Define handler, bind with state const addItemHandler = handler< Item, // Event type { items: Writable } // State type >(({ title }, { items }) => { items.push({ title }); }); interface Output { addItem: Stream<{ title: string }>; } export default pattern, Output>(_ => { const items = Writable.of([] as Array) // Binding returns Stream const addItem = addItemHandler({ items }); // Export in return return { addItem, // This IS Stream<{ title: string }> }; }) ``` The bound handler is the stream. Other patterns or pieces can send events to it via linking.