♻️ Share the Matchable universe between both matchers

This commit is contained in:
tmu committed 2026-09-22 10:54:27 +00:00
1 parent d88a4eeb45
commit 6228b4922d
4 files changed
+24 -17

No files matched your search

+9 -5
View File
@@ -97,9 +97,9 @@ Each factory is two overloads whose order is load-bearing:
#### Decision (2026-09)
`src/matcher-shared.ts` holds the six universe-agnostic pieces both matchers
use: `UnaryFn`, `PatternReturns`, `RedundantFallback`, `HandlerMap`, and the
`PatternKey` / `PatternParam` key projection.
`src/matcher-shared.ts` holds the seven universe-agnostic pieces both matchers
use: `UnaryFn`, `PatternReturns`, `RedundantFallback`, `HandlerMap`, the shared
`Matchable` universe, and the `PatternKey` / `PatternParam` key projection.
#### Why
@@ -107,6 +107,10 @@ use: `UnaryFn`, `PatternReturns`, `RedundantFallback`, `HandlerMap`, and the
keeps the two matchers' message from drifting; the other pieces appear
verbatim in both public signatures or are the same projection over each
matcher's universe.
- **`Matchable` is one definition, not two.** The primitive-union matcher's
universe and the tagged-union matcher's allowed `Tag` values are the same set,
so aliasing them keeps the two matchers from drifting apart on what they
accept (`symbol`/`bigint` rejected once).
#### Rejected
@@ -114,8 +118,8 @@ use: `UnaryFn`, `PatternReturns`, `RedundantFallback`, `HandlerMap`, and the
`Fallback` and `MustBePartial`.** Each is built from its own universe
(`Tags`/`MapTaggedUnion` vs the primitive values); abstracting over the
F-bounded `Handled` constraint that makes the remainder work risks the
contextual typing it exists to preserve. The `PatternKey` / `PatternParam`
projection is the one piece both universes genuinely share.
contextual typing it exists to preserve. `Matchable` and the `PatternKey` /
`PatternParam` projection are the pieces both universes genuinely share.
## Tagged-union matcher