✅ Cover the dispatch throw

An open universe (`getMatcher<string>()`) types its handler map as an index
signature, so a runtime map with fewer keys still satisfies the exhaustive
overload. Calling the matcher with a missing shape reaches the dispatch guard
and throws — no cast needed.
This commit is contained in:
tmu committed 2026-09-18 23:48:59 +00:00
1 parent 8615723c64
commit 0d6a3f1b9b
1 file changed
+15
+15
View File
@@ -326,6 +326,21 @@ test("getMatcherW factory rejects patterns outside its contract", () => {
factory({ x: () => 1 as const });
});
// ============================================================================
// Dispatch — runtime behavior
// ============================================================================
test("getMatcher: an unhandled shape throws without a fallback", () => {
// Arrange — an open universe types its handler map as an index signature,
// so the type system cannot prove the runtime map is exhaustive.
const handlers: Record<string, () => number> = { a: () => 1 };
const matcher = getMatcher<string>()(handlers);
// Act / Assert
assert.equal(matcher("a"), 1);
assert.throws(() => matcher("b"), /Unhandled shape: b/);
});
// ============================================================================
// Autocomplete — the language server is the oracle, not the type system
// ============================================================================