Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/api/src/parsers/attachVariableResolver.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
extend,
type output,
pipe,
safeExtend,
transform,
type ZodMiniAny,
ZodMiniObject,
Expand Down Expand Up @@ -77,15 +77,15 @@ function objectVariableResolverParser<
const $objectParser = objectParser instanceof ZodMiniObject
? objectEntries(objectParser._zod.def.shape).reduce<ZodMiniObject>(
(acc, [key, parser]) =>
extend(acc, {
safeExtend(acc, {
[key]: attachVariableResolver(variablesRegistry, parser),
}),
objectParser,
Comment on lines 79 to 83

Copilot AI Feb 13, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is meant to fix extending object schemas that include refinements, but current tests only cover .refine() on a primitive (z.string().refine(...)) and don't exercise objectVariableResolverParser on a refined object schema (e.g., z.object({...}).refine(...) or superRefine). Please add a regression test that calls Data.create().usePayload(...) with a refined object payload and uses variables within nested properties, ensuring addRules() no longer throws during schema attachment.

Copilot uses AI. Check for mistakes.
)
: objectEntries(objectParser._zod.def.shape).reduce<ZodObject>(
(acc, [key, parser]) =>
acc.extend({
[key]: attachVariableResolver(variablesRegistry, parser),
acc.safeExtend({
[key]: attachVariableResolver(variablesRegistry, parser) as any,

Copilot AI Feb 13, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as any on the value passed to acc.safeExtend() defeats the main benefit of safeExtend (type-level guarantee that the new schema is assignable to the existing property type). It would be better to preserve typing by casting to a narrower type (e.g., based on the existing parser type) or by constructing a typed extension shape first and calling safeExtend once, so TypeScript can keep key/value relationships without falling back to any.

Suggested change
[key]: attachVariableResolver(variablesRegistry, parser) as any,
[key]: attachVariableResolver(variablesRegistry, parser) as $ZodType,

Copilot uses AI. Check for mistakes.
}),
objectParser,
)
Expand Down
Loading