✨ Match boolean, null and undefined

Extend the matcher universe beyond string | number so a union can carry
boolean, null and undefined members. true|false, null and undefined are
not property keys, so handler keys are their stringification while the
callback still receives the real member. Symbols are rejected (a brand
is compile-time only) and bigint is not a property key.
This commit is contained in:
tmu committed 2026-09-21 09:44:44 +00:00
1 parent c32fe08c73
commit 45495fe2a8
5 files changed
+268 -17

No files matched your search

+33
View File
@@ -91,3 +91,36 @@ Each factory is two overloads whose order is load-bearing:
- `Parameters<typeof factory>[0]` resolves only the **last** overload, so it is
not a sound "rejected" oracle for a factory. Factory-negative tests use
`@ts-expect-error` call sites (the test file only — the general ban stands).
## Primitive universe
#### Decision (2026-09)
The universe (`Matchable`) is `string | number | boolean | null | undefined`,
with `boolean` admitted as `true | false`. `symbol` and `bigint` are not.
`boolean`/`null`/`undefined` are not property keys, so handler-map keys are a
projection (`PatternKey`: each member stringified) and `PatternParam` inverts
it, so callbacks receive the real member (`true`, not `"true"`). The popup
offers `true`, `false`, `null`, `undefined` by name (verified over LSP).
#### Why
- Runtime dispatch is unchanged in effect: `handlers[true]` already coerces to
`"true"`. `dispatch` wraps the index in `String()` only because TypeScript
forbids indexing with `boolean`/`null`/`undefined` (`TS2538`).
#### Rejected
- **`symbol`.** A brand is a compile-time phantom — nothing to match at
runtime; the popup cannot offer symbol keys anyway.
- **`bigint`.** Not a valid property key; a stringified key (`"1"`) collides
with numeric `1`.
- **`NaN` / `-0`.** No literal type exists; they stay one `number`.
#### Known issue
- A universe mixing a member with its stringification (`1 | "1"`,
`true | "true"`, `null | "null"`) collapses to one handler key and routes
both members to it. Pre-existing for `1 | "1"`; now reachable for the new
members. Not guarded at the type level.