Skip to content

zod schema with native enum results in internal error #12

@demetrius-mp

Description

@demetrius-mp

reproduction:

const schema = z.object({
	title: z.string(),
	value: z.coerce.number().min(1),
	kind: z.nativeEnum({GRAY: "GRAY", GREEN: "GREEN"}),
	description: z.string().optional()
});

export const load = (async (event) => {
	const form = await superValidate(event, schema);

	return {
		form
	};
}) satisfies PageServerLoad;

if i set a .default("GRAY") to the enum field, it works ok

not sure if this is intentional, but one problem i noted with setting a default value is that it removes the required constraint.

tried submitting the form and got the following error: Error: Unsupported Zod default type: ZodNativeEnum

tried using z.enum and it works ok

Is there a plan on adding native enum support? the motivation for this support could be, for example, using the Enum Objects auto generated by prisma when defining an Enum Schema.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions