Sikari
Sikari
ZZod
Created by Gludek on 5/11/2024 in #questions
Gludek - Just to confirm z.string().email() can...
Perhaps you're looking for:
const schema = z.literal("").or(z.string().email());
const schema = z.literal("").or(z.string().email());
8 replies
ZZod
Created by Gludek on 5/11/2024 in #questions
Gludek - Just to confirm z.string().email() can...
Your form most likely is not passing null or undefined, most likely you have ""
8 replies
ZZod
Created by Gludek on 5/11/2024 in #questions
Gludek - Just to confirm z.string().email() can...
I don't see why it wouldn't be able to, nullish just adds undefined | null to the type.
8 replies
ZZod
Created by shadi on 4/28/2024 in #questions
shadi - hey everyone, i've been struggling with...
You have to manually type either direction of the types, for example:
const ActionSchema = z.object({ ... });

const BranchPromptSchema = z.object({ ... });

const BranchSchema = z.object({
prompt: BranchPromptSchema,
branches: z.lazy(() => z.array(ConfigSchema)),
});

type Config = {
name: string;
branch: z.infer<typeof BranchSchema>;
actions: undefined;
} | {
name: string;
branch: undefined;
actions: z.infer<typeof ActionSchema>[];
};

const ConfigSchema: z.ZodType<Config> = z.union([
z.object({
name: z.string(),
branch: BranchSchema,
actions: z.undefined(),
}),
z.object({
name: z.string(),
branch: z.undefined(),
actions: z.array(ActionSchema),
}),
]);
const ActionSchema = z.object({ ... });

const BranchPromptSchema = z.object({ ... });

const BranchSchema = z.object({
prompt: BranchPromptSchema,
branches: z.lazy(() => z.array(ConfigSchema)),
});

type Config = {
name: string;
branch: z.infer<typeof BranchSchema>;
actions: undefined;
} | {
name: string;
branch: undefined;
actions: z.infer<typeof ActionSchema>[];
};

const ConfigSchema: z.ZodType<Config> = z.union([
z.object({
name: z.string(),
branch: BranchSchema,
actions: z.undefined(),
}),
z.object({
name: z.string(),
branch: z.undefined(),
actions: z.array(ActionSchema),
}),
]);
4 replies