Id in zod schema for frontend and backend?

Hi guys I am saving a "client" in my backend for that I have following basic schema, which is used in my frontend and backend
const clientSchema = z
.object({
id: z.string().nullish(),
const clientSchema = z
.object({
id: z.string().nullish(),
I am not sure should I set the id to nullish or should it no be nullish?
7 Replies
utdev
utdev3y ago
Because if I fetch the client I should have a id, but if I create a client I don't have an id, only after saving Using the type in my frontend like this is that makes a difference
interface ClientsTableProps {
data: z.infer<typeof clientSchema>[]
}
interface ClientsTableProps {
data: z.infer<typeof clientSchema>[]
}
Neto
Neto3y ago
you can merge schemas
Neto
Neto3y ago
Neto
Neto3y ago
but i would prefer three schemas
Neto
Neto3y ago
like this
utdev
utdev3y ago
that makes sense to different schemas for different actions if needed thanks
Neto
Neto3y ago
last time i did a upsertSchema, and later a merged with the id schema so i had both create and update schema with same fields
Want results from more Discord servers?
Add your server