Repository navigation
fix(v4): align record keys and intersection strictness with TypeScript - #6412
Merged
Merged
Conversation
β¦enumerable An enumerable key schema (z.enum, z.literal([...])) declares which keys the record owns, so a key outside that set is unrecognized. A non-enumerable one (regex, refine) is a constraint every key must satisfy, so a failing key is invalid. Only the first is reconcilable against the other side of an intersection, which handleIntersectionResults already does for unrecognized_keys. The branch that emitted the issue keyed off def.partial rather than the key schema, so partialRecord(z.enum([...])) reported invalid_key and its keys were never reconciled -- the object side of an intersection could not claim its own keys. Fixes #2200, #2573.
A record's key schema declares which keys that record is responsible for. It
is not a predicate every key in the result must satisfy. TypeScript agrees:
in `{name: string} & Record<\`S_\${string}\`, string>` the index signature
constrains only the keys matching it, so `name` is accepted, while a matching
key with the wrong value type is still an error.
Zod's inferred types already match TypeScript here, but the runtime rejected
the object's own keys with invalid_key, so z.infer accepted values the parser
threw on. Two changes:
- partialRecord with an enumerable key schema now reports an out-of-set key as
unrecognized_keys, like z.record(z.enum([...])) already did. The branch keyed
off def.partial rather than off the key schema.
- handleIntersectionResults reconciles a record's invalid_key the same way it
already reconciles unrecognized_keys, so a key one side does not govern is
reported only when neither side governs it.
Standalone records are unchanged: a key outside the key schema is still an
error, matching TypeScript's excess-property check on a fresh literal.
Fixes #2200, #2573.
β¦logic unrecognized_keys describes the shape of the input, not the validity of the parsed value, so it no longer aborts the schema it came from. A strict operand inside an intersection now runs its own checks, refinements and transforms, a nested default still applies, and an extra key no longer suppresses the other errors on the same object. The parse still fails. A pipe keeps its rule that any issue stops it, so a failing refinement never feeds its transform -- the one exception is unrecognized_keys, where the value handed downstream is identical whether or not the extra key was present.
Contributor
|
This run was cancelled π The workflow was cancelled before completion. Please check the link below for details. |
This was referenced Aug 14, 2026
colinhacks
added a commit
to colinhacks/frizz
that referenced
this pull request
Aug 17, 2026
The queue showed an "Awaiting" card immediately above an "Awaiting background work" card, both about the same rest. Maintainer 2026-08-13: "I keep seeing duplicates like this." It is a seam between two correct changes. Since `pr-watch` stopped carrying a park action (2026-08-13), an awaiting fence on a watched PR has nothing to offer, so it falls back to a bare "Awaiting" heading β while the resting card below it states the same wait with the counts and the only control. The heading was the whole of the duplication. So a fence with NO park action, on a thread whose resting card is showing, drops its chrome and keeps its content: the worker's own prose, rendered as the ordinary final message it is. A fence with a real action β a `human` gate, a future `timer` β still earns its card, because that control lives nowhere else. Guarded on `awaitingBackground` rather than assumed: a thread parked on a watcher with no live shell or sub-agent shows no resting card, and dropping the chrome there would leave the wait unstated. The refs went the same way one level down. The watcher rows under the prompt box already list every watched PR, so printing the fence's links too put `colinhacks/zod#6412` twice on one card; they now render only when those rows are absent. Verified against a rebuild of the reported shape β two `pr-watch` hints, a live background shell, a resting thread: one statement of the wait, each PR named once. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
7 of 14 tasks
This was referenced Sep 1, 2026
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Makes a record's key schema behave the way TypeScript treats an index signature, and stops an unrecognized key from suppressing the rest of a schema.
A record's key schema governs its own keys, not every key
nameis the object's key, not the record's. TypeScript agrees β in{name: string} & Record<S_${string}, string>the index signature constrains only the keys matching it, while a matching key with the wrong value type is still an error.z.inferalready matched TypeScript here; the parser did not, so the runtime rejected values the inferred type accepted.This holds for every key-schema flavor:
z.enum,z.literal([...]),z.string().regex(),z.templateLiteral(). Two changes get there.$ZodRecordchose its issue code fromdef.partialrather than from the key schema, soz.partialRecord(z.enum([...]))reportedinvalid_keywherez.record(z.enum([...]))reportedunrecognized_keys; it now classifies on the key schema. AndhandleIntersectionResultsreconciles a record'sinvalid_keythe same way it already reconcilesunrecognized_keys, so a key one operand does not govern is reported only when no operand governs it.The reconciliation rule itself is unchanged: report a key only when every operand objects to it. A stripping schema never objects, so it never contributes. Standalone records are unchanged β a key outside the key schema is still an error, matching TypeScript's excess-property check on a fresh object literal.
An unrecognized key no longer aborts the schema it came from
unrecognized_keysdescribes the shape of the input, not the validity of the parsed value, so it is now continuable at every emission site. A strict operand inside an intersection runs its own checks, refinements and transforms; a.default()inside a nested intersection applies. The parse still fails.A pipe keeps its rule that any issue stops it, so a failing refinement never feeds its transform and
z.string().refine(isJSON).transform(JSON.parse)still fails cleanly rather than throwing. The single exception isunrecognized_keys, where the value handed downstream is identical whether or not the extra key was present.Supersedes #5905, #6234 and #6248. Fixes #2200. Fixes #2573. Fixes #4017. Fixes #5663.