/** * Type-safe custom event emission for components. */ type NoDetail = undefined | undefined | never; type KeysWithoutDetail> = { [P in keyof T]: [T[P]] extends [NoDetail] ? P : never; }[keyof T]; /** * Typed emit function: only declared event names type-check, and `detail` is * required exactly when its payload type is non-void. Dynamic event names must * be cast at the call site — an intentional speed bump, not a silent escape. */ export type EmitFn> = { >(event: K): boolean; >>(event: K, detail: T[K]): boolean; }; /** * Returns a typed `emit()` function bound to the current component's host element. * Call once during `setup()` — the `Emits` type parameter maps event names to * their `detail` payload type. * * Every event is dispatched `cancelable: true`, and `emit()` returns `dispatchEvent`'s * own boolean result — `false` when a listener called `preventDefault()`. Components * that need to know whether a listener cancelled an event (e.g. to skip a default * action) read this return value directly instead of hand-rolling `dispatchEvent`. * * Events do **not** cross the shadow boundary by default (`composed: false`) — a * listener outside the component's shadow root will not observe them. Dispatch a * `CustomEvent` with `composed: true` by hand if an event must escape the shadow root. * * @example * ```ts * type Events = { close: undefined; change: { value: string } }; * * setup(props) { * const emit = useEmit(); * emit('close'); * * const notCancelled = emit('change', { value: 'ok' }); * if (notCancelled) props.value.value = 'ok'; * } * ``` */ export declare const useEmit: = Record>() => EmitFn; export {}; //# sourceMappingURL=emit.d.ts.map