Skip to content

Commit e008e50

Browse files
committed
fix: avoid merging zod defaults neither is not an object closes #4186
1 parent 71a9dd9 commit e008e50

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

packages/zod/src/index.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ZodObject, input, output, ZodDefault, ZodSchema, ParseParams } from 'zod';
22
import { PartialDeep } from 'type-fest';
33
import type { TypedSchema, TypedSchemaError } from 'vee-validate';
4-
import { isIndex, merge } from '../../shared';
4+
import { isIndex, isObject, merge } from '../../shared';
55

66
/**
77
* Transforms a Zod object schema to Yup's schema
@@ -43,8 +43,11 @@ export function toTypedSchema<
4343
} catch {
4444
// Zod does not support "casting" or not validating a value, so next best thing is getting the defaults and merging them with the provided values.
4545
const defaults = getDefaults(zodSchema);
46+
if (isObject(defaults) && isObject(values)) {
47+
return merge(defaults, values);
48+
}
4649

47-
return merge(defaults, values);
50+
return values;
4851
}
4952
},
5053
};
@@ -71,9 +74,9 @@ function joinPath(path: (string | number)[]): string {
7174

7275
// Zod does not support extracting default values so the next best thing is manually extracting them.
7376
// https://github.com/colinhacks/zod/issues/1944#issuecomment-1406566175
74-
function getDefaults<Schema extends ZodSchema>(schema: Schema): any {
77+
function getDefaults<Schema extends ZodSchema>(schema: Schema): unknown {
7578
if (!(schema instanceof ZodObject)) {
76-
return;
79+
return undefined;
7780
}
7881

7982
return Object.fromEntries(

0 commit comments

Comments
 (0)