fix(validator): resolve inline rule overload#43
Conversation
Add tests for 1-arg anonymous form and 1-arg with explicit TSubject to guard against overload resolution regressions.
Review follow-up: added missing test coverage for anonymous overload variantsThe overload reordering in this fix is correct, but the original test file only covered the 2-argument named forms. Since the fix is fundamentally about overload resolution with explicit type parameters, I've added two test cases:
All 4 tests pass, lint is clean. |
The args.reverse() pattern was non-obvious and relied on in-place mutation to destructure positional args in reverse order. Replace with a simple args.length check that reads left-to-right, matching the overload signatures. Also remove stale commented-out code. Add type-level tests using expectTypeOf for all overload variants and a runtime test for the both-type-params-explicit form.
Follow-up: implementation improvements and type-level test coverage1. Replaced
|
| Call pattern | Expected rule[0] type |
|---|---|
createInlineRule('hasLength', ...) |
'hasLength' (literal) |
createInlineRule<string>('hasLength', ...) |
string (widened) |
createInlineRule(predicate) |
InlineRuleName |
createInlineRule<string>(predicate) |
InlineRuleName |
createInlineRule<string, 'hasLength'>(...) |
'hasLength' (literal) |
These assert the exact return type at compile time, catching any future overload regressions that runtime tests would miss.
4. Added runtime test for both-type-params-explicit form
createInlineRule<string, 'hasLength'>('hasLength', ...) was not covered by any test. Added.
All 358 tests pass, lint clean, typecheck clean.
Summary
Closes #40
Verification