Description and expected behavior
makeModelSchema: DateTime fields infer as unknown in z.input.
It breaks my usage of react-hook-form.
export const PostSchema = schemaFactory.makeModelSchema("Post", {
optionality: "defaults", // fields that have a @default or @updatedAt attribute become optional
omit: { authorId: true }, // scalar fields linking to relations are omitted
});
export type PostFormData = z.infer<typeof PostSchema>;
type _DebugOutput = z.infer<typeof PostSchema>["createdAt"];
// type _DebugOutput = Date | undefined
type _DebugInput = z.input<typeof PostSchema>["createdAt"];
// type _DebugInput = unknown
// @zenstackhq/zod maps DateTime to z.ZodType<Date> instead of z.ZodDate,
// which makes z.input degrade to unknown.
// This breaks any library that uses the input type (like @hookform/resolvers).
// The fix would be to use z.ZodDate (or the concrete coercion type) in FieldTypeZodMap.
Environment (please complete the following information):
- ZenStack version: 3.6.4
- Database type: Postgresql
- Node.js version: v24.15.0
- Package manager: npm
Additional context
With react-hook-form
const {
register,
handleSubmit,
reset,
watch,
setError,
formState: { errors, isSubmitting, isSubmitSuccessful },
} = useForm<PostFormData>({
resolver: zodResolver(PostSchema),
defaultValues: {
title: post?.title ?? "",
content: post?.content ?? "",
published: post?.published ?? false,
},
});
zodResolver(PostSchema) has type issues.
Idem for Decimal, Bytes, ...
Description and expected behavior
makeModelSchema: DateTime fields infer as unknown in z.input.
It breaks my usage of react-hook-form.
Environment (please complete the following information):
Additional context
With react-hook-form
zodResolver(PostSchema) has type issues.
Idem for Decimal, Bytes, ...