zod
zod copied to clipboard
Is it possible to create a zod enum from a string literal type
What zod fn should I use to make the BarSchema valid?
type Foo = 'foo' | 'bar'; // generated
interface Bar {
foo: Foo,
id: string,
}
export const BarSchema = z.object({
foo: z.enum(Foo), // what should this be?
id: z.string()
}) satisfies z.ZodSchema<Bar>;
I know I can redefine the Foo type like:
foo: z.enum(['foo', 'bar'])
But the point is not to redefine the generated types.