Repository navigation
fix(v4): reject tuple holes before required defaults - #5900
Conversation
|
TL;DR — Fixes tuple parsing to reject absent optional-output slots when a later slot has required output (e.g. Key changes
Summary | 2 files | 4 commits | base: Reject tuple holes that precede required output
The fix introduces a
|
There was a problem hiding this comment.
Reviewed — no issues found.
Task list (4/4 completed)
- Checkout PR and read the diff
- Read changed files and trace logic
- Draft review comments
- Submit review
Claude Opus | 𝕏
There was a problem hiding this comment.
No new issues. Reviewed the following changes:
- Replaced inline
hasRequiredOutputAfterboolean array with a pre-computedoptoutStartindex, eliminating an O(n) allocation inhandleTupleResults - Extracted
getTupleOptStarthelper to compute bothoptinStart(input-length validation) andoptoutStart(output-shaping truncation) without the[...items].reverse().findIndex()copy+allocation - Added
optoutStartparameter tohandleTupleResults; truncation condition changed from!hasRequiredOutputAfter[i]to the equivalenti >= optoutStart - Added test for
.exactOptional()before a defaulted slot, asserting parse failure and correct type inference
Claude Opus | 𝕏
|
Landed in Zod 4.4 |

Summary
exactOptional()before.default()plus refined optional async/sync parity.Test plan
pnpm vitest run packages/zod/src/v4/classic/tests/tuple.test.tspnpm vitest run packages/zod/src/v4/classic/tests/optional.test.ts