Steve - I was wondering if there is a certain w...
I was wondering if there is a certain way to further optimize the
.refine
. And if possible, also improve the typing of it.
Basically also wondering I would be able to type TipTapTextDto['marks']
In a way that I define it to be an array of TipTapMarkDto
but also it to have at least one IdentifierMarkDto
, no matter the order in which the TipTapMarkDto
present themselves.
```ts...Solution:
You could use something like a brand to indicate to the consumer that it has been verified to contain a certain element, but the type system still wouldn't know how to encode that information, so you'd still have to code defensively
Steve - I have this unique case where I want to...
I have this unique case where I want to filter out elements that do not match my union. Is there any way to do that using zod?
Basically:
z.union([ ... ]).strip()
...Solution:
```ts
export const TipTapDocumentDto = z
.object({
type: z.literal("doc"),
attrs: z.object({...
Discriminated union default value on the discriminator
Discriminated union default value on the discriminator
Solution:
```ts
const BaseReservation = z.object({
reservationId: z.number(),
reservedBy: z.string(),
});...
Stephan Meijer - What was the deal with union a...
What was the deal with union and transform again?
```ts
import { Heading, Paragraph, Text } from '@toegang-voor-iedereen/document-spec-types';
import { v4 as uuidv4 } from 'uuid';...
Whimsy - .optional() makes the type optional? l...
.optional() makes the type optional? like using it with
z.boolean().default(false)
makes it boolean | undefined
Stephan Meijer - How does Zod's transform funct...
How do Zod's transform work with schema's inside other schema's that also have
transform
on them?Solution:
If that’s what you’re asking, inner transforms get run first
CommandMC - z.function().args() seems to forget...
z.function().args()
seems to forget brand
s?
Hello. Using a brand
ed schema as an argument to a Zod function (z.function()
) & then inferring the type of that function doesn't seem to be working correctly, the argument type just reverts to its non-branded type
TS Playground example of my issue...Stephan Meijer - When exporting myschema's and ...
When exporting my schema's as a package and then importing them, I get errors...
...
ESLint: Unsafe member access .parseAsync on an `error` typed value.(@typescript-eslint/no-unsafe-member-access)
ESLint: Unsafe member access .parseAsync on an `error` typed value.(@typescript-eslint/no-unsafe-member-access)
Solution:
The basic issue is that typescript-eslint is getting an error from its own internal typescript compiler message. Usually restarting can help, but if it persists there might be a configuration issue in eslint or in the ide plugin
Whimsy - hey is there a way to tell zod what ki...
hey is there a way to tell zod what kind of schema shape i want from type, instead of opposite infering type from schema?

unreal - Hello, i have this schema tsconst som...
Hello, i have this schema ```ts
const someSchema = z.object({
description: z
.string()
.min(20, 'Min description length is 20')...

Luan Mário - Guys, I need help, I'm using discr...
Guys, I need help, I'm using discriminatedUnion to join the schemas, but I'm not able to pass more than one defaultValues when starting, it's only accepting one
fahad19 - Hi folks 👋 I am using Zod for lint...
Hi folks 👋
I am using Zod for linting functionality in an open source project of mine: https://featurevisor.com/docs/linting/
one of the use cases I have hit is being able to access the parent/root object when inside .superRefine() of a nested object. I tried reading the docs, and couldn't figure out if it is possible....
Solution:
I tackled the problem by doing superRefine() at root: https://github.com/featurevisor/featurevisor/pull/320
EagleV - hi, how can I test zod z.date() using ...
hi, how can I test zod z.date() using postman? I've tried to pass a ISO date like
2024-08-01T12:00:00Z
but it's not workingSolution:
you can use
z.coerce.date()
zod will parse your input to Date
https://zod.dev/?id=coercion-for-primitives...