Open MrMysterius opened 3 months ago
It might not be a problem with the extend/merge, since this does not work as well. ¯\_(ツ)_/¯
export function ResultCreator<T extends z.ZodTypeAny>(data_schema: T) {
let merged = z.object({
success: z.boolean(),
message: z.string().optional(),
errors: z.array(z.any().optional()).optional(),
data: data_schema.optional(),
});
return function (options: z.input<typeof merged>) {
let res = merged.safeParse(options);
if (!res.success) throw res.error;
return res.data;
};
}
The following is my code, where in the
createParser
function, where on the return it wants all properties in the schema from theResultCreator
/createResult
function even though the omitted properties are optional and shouldn't be required.The two Errors look the following in order of lines:
Result.ts
:Parser.ts
I believe this is not the expected behavior, since the properties should be optional as defined and not required. Also I hope I am not a big dumb dumb, and this behavior is normal.