You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This made doing deeply nested defaults with overrides very simple.
In v4, you get a TypeScript error on the child: MyChildSchema.default({}), line:
ts: No overload matches this call.
Overload 1 of 2, '(def: { num: number; text: string; }, params?: string | { error?: undefined; } | undefined): ZodDefault<ZodObject<{ num: ZodDefault<ZodNumber>; text: ZodDefault<ZodString>; }, {}>>', gave the following error.
Argument of type '{}' is not assignable to parameter of type '{ num: number; text: string; }'.
Type '{}' is missing the following properties from type '{ num: number; text: string; }': num, text
Overload 2 of 2, '(def: () => { num: number; text: string; }, params?: string | { error?: undefined; } | undefined): ZodDefault<ZodObject<{ num: ZodDefault<ZodNumber>; text: ZodDefault<ZodString>; }, {}>>', gave the following error.
Argument of type '{}' is not assignable to parameter of type '() => { num: number; text: string; }'.
Type '{}' provides no match for the signature '(): { num: number; text: string; }'.
This feels like unwanted behaviour, because surely the defaults mean that the empty object {} would be valid (IE uses child's default).
If there's a better way to do this I am interested.
The text was updated successfully, but these errors were encountered:
radiosilence
changed the title
v4: cannot assign empty object to schema with defaults - regression?
v4: cannot empty object as default for schema with defaults - regression?
May 2, 2025
radiosilence
changed the title
v4: cannot empty object as default for schema with defaults - regression?
v4: cannot use empty object as default for schema with defaults - regression?
May 2, 2025
In v3, you could do:
This made doing deeply nested defaults with overrides very simple.
In v4, you get a TypeScript error on the
child: MyChildSchema.default({}),
line:This feels like unwanted behaviour, because surely the defaults mean that the empty object
{}
would be valid (IE uses child's default).If there's a better way to do this I am interested.
The text was updated successfully, but these errors were encountered: