import type { ValueOf } from "type-fest"; // The primitive-union and tagged-union matchers differ in their universe, but the // handler/fallback plumbing is identical; these are the shared pieces. The // boundary is deliberate: `Handlers`, `Fallback` and `MustBePartial` stay with // each matcher because they are built from its universe. See development/library.md. // A handler: one universe member in, one return value out. export type UnaryFn = (shape: T) => R; // `Extract` drops optional handlers (`undefined`) so `PatternReturns` also works // when `P`'s constraint has optional keys. export type PatternReturns

= ReturnType< Extract, (...args: never[]) => unknown> >; // The diagnostic raised when a fallback is supplied for an already-exhaustive // handler map. Each matcher's `MustBePartial` folds it into `Handled`'s // constraint so the guard is checked after inference. export interface RedundantFallback { readonly "every case is already handled, so the fallback is redundant": never; } // The runtime dispatch map the handler maps and fallback erase to. export type HandlerMap = Record< string | number, UnaryFn | undefined >;