✅ 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:
1 parent
8615723c64
commit
0d6a3f1b9b
1 file changed
+15
@@ -326,6 +326,21 @@ test("getMatcherW factory rejects patterns outside its contract", () => {
|
|||||||
factory({ x: () => 1 as const });
|
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
|
// Autocomplete — the language server is the oracle, not the type system
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|||||||
Reference in new issue
Block a user