Repository navigation
fix: check sparse-array holes in the isArrayOf type guard - #455
Conversation
The boolean path used Array.prototype.every(), which skips holes, while validate() and validateAll() visit every index. The guard now visits every index too, so a hole is checked as undefined on all paths. Closes #450 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019BJENnU8SXcDH2Tcx5EWE4
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #455 +/- ##
=======================================
Coverage 98.46% 98.46%
=======================================
Files 52 52
Lines 3055 3057 +2
Branches 327 327
=======================================
+ Hits 3008 3010 +2
Misses 46 46
Partials 1 1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
gjbkz
left a comment
There was a problem hiding this comment.
Reviewed commit 43904af416b277c018477dd4e4af80d33f85cd2c. No actionable issues found in this change.
Visiting each array index aligns the boolean guard with diagnostic traversal: holes are checked as undefined. The regression coverage checks empty, fully sparse, mixed, explicit-undefined, and dense arrays with both string and optional-string element checkers across the boolean, test(), validate(), and validateAll() paths.
Validation: the complete source unit-test suite passed locally on this reviewed version, and the GitHub Actions test workflow for this commit completed successfully. The latest head is unchanged from the locally tested version.
After merging main, the explicit index loop pushed the minified UUID checker bundle to 5924 bytes, over the 5916-byte budget enforced by test/package.test.ts. findIndex() also visits holes as undefined, and keeps the bundle at 5877 bytes. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019BJENnU8SXcDH2Tcx5EWE4
Requested by Kei · project thread
Before:
isArrayOf(isString)(new Array(1))returnedtrue, narrowing a sparse array tostring[], whilevalidate()andvalidateAll()rejected the same input at path[0].After: holes are checked as
undefinedon every path, so the guard,test(),validate()andvalidateAll()agree. A hole failsisArrayOf(isString)and passesisArrayOf(isOptionalOf(isString)).How: the boolean path now uses
Array.prototype.findIndex(), which visits holes asundefined, instead ofevery(), which skips them. An earlier explicit index loop pushed the minified UUID bundle over the 5916-byte budget intest/package.test.ts(5924 bytes) once #453 and #454 were merged; withfindIndex()it is 5877 bytes. Tests cover empty, fully sparse, mixed, explicit-undefinedand dense arrays against both checkers; the test fails onmainand passes here.Closes #450
🤖 Generated with Claude Code
https://claude.ai/code/session_019BJENnU8SXcDH2Tcx5EWE4