Zod

Z

Zod

Discussion for Zod, a runtime type library for TypeScript, and the surrounding ecosystem of libraries.

Join

MHD Alaa - Hi everyone, first time here.I’m ju...

Hi everyone, first time here. I’m just wondering is there is a place to contribute to v4.zod.dev website. Like if there is typos in the provided examples, what is the proper way to point it out? ...
Solution:
Hi, you need to fork the repo and then raise MR to the zod repo. All the work is being done under v4 branch (have a look on github) thanks for trying to contribute to Zod
Message Not Public
Sign In & Join Server To View

MattIPv4 - :WaveDoggo: I think this might be a ...

:Wave_Doggo: I think this might be a Zod Q at this point rather than TypeScript itself -- I have a custom type that relies on import() types. I've figured out how to partially preserve them when generating declaration files, but I'm still getting some unknowns included instead of references to the import() types.
Solution:
Ahah! ```ts type ImagePng = (typeof import(".png"))["default"]; type ImageJpg = (typeof import(".jpg"))["default"];...

Maxiviper117 - I'm working on validating an obj...

I'm working on validating an object where: - Some property keys are known and expected. - Other extra/unknown keys are allowed only if they follow a specific pattern. ...
Solution:
If you wish to get more type safety, here is something: https://tsplay.dev/N5oVdW

MattIPv4 - :WaveDoggo: Hey Zod experts. Given a...

:Wave_Doggo: Hey Zod experts. Given an arbitrary Zod schema, is there a way I can strip refinements off any string types?

Gludek - Hey,Quick question, is there any way ...

Hey, Quick question, is there any way to validate blobs/file uploads? TBH I'm not even sure if it even makes sense to do....

Leozinn - const AuthorSchema = z.object({ ...

``` const AuthorSchema = z.object({ name: z.string().max(256), url: z.string().url().optional().nullable(), icon_url: z.string().url().optional().nullable(),...
No description

Leozinn - i'm compiled my project, and interfac...

i'm compiled my project, and interfaces.d.ts return this... How am I going to use typing in my project, if it is like a zod object?...
No description

hinogi - tsconst a = z.object({ foo: z.strin...

```ts const a = z.object({ foo: z.string() }) ...
Solution:
ok so foo has to be foo: null | undefined and {} is not a valid solutions. also, if null, the key will persist, if undefined the key is gone 😄 thanks playground

versace - hey!I am currently investigating wh...

hey! I am currently investigating what the best approach for using header validation through zod would be in regards to key case sensitivity. i'm currently in a situation where I need to have support for all headers to be supported regardless of how the casing looks when sent in from the request. any suggestions?...
Solution:
Do you need to preserve the case of the incoming headers? You could transform them at runtime with .toLowerCase() and then build your schema on the lowercased keys.

Dawson - Can someone sanity check this for me? ...

Can someone sanity check this for me? I'm trying to use an async refinement to validate name uniqueness, but the parse is always succeeding: ```ts z.string() .min(1)...

Torbjørn - Hi!We use zod to validate data com...

Hi! We use Zod to validate data coming from sanity CMS. Sanity has this fancy preview mode that uses @vercel/stega a package that encodes invisible strings into its output....
Solution:
if your goal is to keep the types as if the stega matched ones aren't there you can do something like this ```ts const MyStringSchema = z.union([...

Haddok - hi , i have defined a schema where i a...

hi , i have defined a schema where i am accessing a few fields using shape for some specific scenario i tried using myschema.shape[fieldname].safeparse(value) ...

unnreaal - tsconst schema = z.coerce.string()....

```ts const schema = z.coerce.string().optional(); // type Schema = string | undefined; type Schema = z.infer<typeof schema>;...

Steve - Is there any data on performance compar...

Is there any data on performance compared to @effect/schema preferably specifically to recursive types? ^[1] ^[2]

Steve - Would this be valid, or would it possib...

Would this be valid, or would it possibly parse data as unknown while there could be a more specific match? ```ts import { ContentType } from '@/api/ContentType' import { TipTapDocumentDto } from '@/tiptap/schemas/translations/Document'...
Solution:
order matters in union definitions (they're run in series one after the other), so as long as you put the more specific ones first, it'll match the more specific ones and not the unknown one.

Bence (Arzen) - Hi guys 🙂 Is there a way to cr...

Hi guys 🙂 Is there a way to create a recursive record schema? I know how to make recursive schema using an object, but I am curious if it is currently possible to do with records. The keys can be anything in my data, that's why I'm trying to use a record.

Steve - We have some performance issues with bi...

We have some performance issues (in browser) with big blobs of json using transform() and lazy(). Any general tips and tricks to make it more performant?
Solution:
I don't think there is much that can be done there: if you are making big transforms to large blobs of JSON data, Zod is an expensive way to do it (since we're doing checking and transforming).

Z4RM - Hello! I'm going to write a fullstack ap...

Hello! I'm going to write a fullstack application, and for types consistency between my backend and frontend, I'm looking at Zod and implementing it in my app. However, I'm running into an issue: I want to include the error object returned from the parse method, but I don't find how I can "include" it in a z.object. I'm not sure if what I say is very clear, so here is an explanation in code: ```ts...
Solution:
You could use z.custom for this

Whimsy - is there any function or way to make s...

is there any function or way to make schema fully optional, like literally every property, every nested lazy model? this does work, but is it like correct, is there anything seriously wrong with it or ```ts export function deepPartialify(schema: z.ZodTypeAny): z.ZodTypeAny {...

Steve - How much overhead does Zod have? How pe...

How much overhead does Zod have? How performant is it actually?
Next