Skip to content

Commit 1a256c6

Browse files
committed
fix lazy schema unwrapping
1 parent 8e5ab96 commit 1a256c6

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

packages/runtime/src/zod-utils.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,5 +121,14 @@ function countUnrecognizedKeys(issues: Z.ZodIssue[]) {
121121
}
122122

123123
function unwrapLazy<T extends Z.ZodSchema>(z: typeof Z, schema: T | Z.ZodLazy<T>): T {
124-
return schema instanceof z.ZodLazy ? schema.schema : schema;
124+
if (!(schema instanceof z.ZodLazy)) {
125+
return schema;
126+
}
127+
if ('unwrap' in schema && typeof schema.unwrap === 'function') {
128+
return schema.unwrap();
129+
} else if ('schema' in schema) {
130+
return schema.schema as T;
131+
} else {
132+
throw new Error('Unable to determine how to unwrap a lazy schema with this zod version.');
133+
}
125134
}

0 commit comments

Comments
 (0)