Join the community to ask questions about Zod and get answers from other members.

Join Server

janglad - Quick question, .pick allows non exis...

Quick question, .pick allows non existing keys. Is this supposed to be the case and am I missing something or is this a bug?
No description

Yamereee - 👋 Hello Zod Wizards! A Question wh...

👋 Hello Zod Wizards! A Question when using coerce with my API responses, I have a schema here Note that LastModified is a string but is an ISO date string ```typescript...
If you want better type information, you can use z.string().transform((dateString) => new Date(dateString)) especially if you know the input is and should be a string rather than something else coercible to a date (like number for instance)
Message Not Public
Sign In & Join Server To View
DTDavid Tejada10/27/2023

David Tejada - Hi. I have the following functio...

Hi. I have the following function which I have simplified for the example. The type Storage is inferred from the zod object zStorage. I would like to know why the type assertion is necessary here. Shouldn't the return type be inferred automatically when using parse? ```typescript export async function retrieve<T extends keyof Storage>( key: T,...
yea sorry you would indeed need a generic for that

Kas.st - Hi everyone, I have a schema with an e...

Hi everyone, I have a schema with an enum: ```javascript const schema = z.object({ foo: z.enum(["foo", "bar", "baz"]) })...
```ts // Type level type EnumValue = typeof schema["shape"]["foo"]["options"][number]; // Runtime (with types also)...
Message Not Public
Sign In & Join Server To View

kiqaps - hey guys, am I doing something wrong? ...

hey guys, am I doing something wrong? why does the infered type has optional mark?
No description
Double check strict: true and strictNullCheck: true in your tsconfig
Message Not Public
Sign In & Join Server To View
No description

janglad - deepPartial has been depreciated rece...

deepPartial has been depreciated recently (https://github.com/colinhacks/zod/commit/edc3a67e77d33979b3ee9e071557b4ca53298c55), however the docs don't reflect this and it's not clear to me what it should be replaced with. Anyone have any idea?

zerokelvin - Why is MySchema.parse making optio...

Why is MySchema.parse making optional all of the properties of my schema? How do I stop it from doing this? Stackblitz: https://stackblitz.com/edit/typescript-pnkeqy?file=index.ts,package.json ```ts...
LMLuan Mário10/17/2023

Dealing with form input with z.coerce.date

Hey guys, How do I make z.coerce.date() required, with zod and react hook form...

Hey I have a schema where I need to

Hey, I have a schema where I need to validate one field based on API request. Basically I need to check if given code has not been used already. The issue is that for some reason if I use await in superRefine it makes other fields act weird. Like if they are validaiting twice/waiting for validation of the API based field, and it sometimes leads to situation where it shows field as invalid even though it has valid value.

hey I m getting this error which is

hey, I'm getting this error which is confusing to me. ```js ZodError: [ { ...

Merge on a wrapped object schema

Hey how can I merge/intersect zod object with discriminated union so I have .extend later available? Main type is like this ```ts z.object({...

i ve got a question about `pipe` and

i've got a question about pipe and coerce. the shape of my data is a bit funky so sorry if it's a bit confusing. the input for the schema is an array of strings, that will either a number like ["7"] or an iso date (without time data), like ["2023-01-01", "2023-02-02"]. i've currently got the schema as: array(string().pipe(union([coerce.number(), coerce.date()]))) with the intention that it will accept a string, then coerce it to either a number or a date. ...

Heya For some reason if I use `z any `

Heya! For some reason, if I use z.any(), z.unknown() or z.custom() as a value in z.object(), it's always inferred as optional, even though other values are correctly inferred as required. I even tried chaining .required() on the object, doesn't help. Couldn't find any hints in the docs about this behavior.
No description

Discriminated Unions

Yeah, I was wondering about that, but can't figure out how to combine discriminated unions with other fields. Like in this case: ```ts const Schema = z.object({ unrelated1: z.string(), unrelated2: z.number(),...

Date validation

Question: Any good examples on how to do min/max date validation with zod?