Replies: 1 comment 1 reply
-
After some more research I see that it only happens with Works: import z from "zod";
export type WorkingType = {
someBoolean: boolean;
};
export const workingSchema: z.ZodType<WorkingType> = z.object({
someBoolean: z.boolean(),
}); Doesn't work: import z from "zod";
export type NonWorkingType = {
someBoolean: boolean;
};
export const nonWorkingSchema: z.ZodType<NonWorkingType> = z.object({
someBoolean: z.boolean().default(false),
}); |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm trying to get ZodType to work with booleans. If I use
z.ZodType<T>
I need to have the boolean property as a nullable boolean to avoid the following error:(Adding
.required
doesn't help, either.)As you can see, it works if the boolean is nullable:
On the other hand, if I don't use
z.ZodType<T>
, and usez.infer<>
instead, I get the correct type with a not nullable boolean:(Adding
.partial
creates a nullable type, as expected.)Anything I'm missing? Is it expected behaviour, or a bug?
Using
z.ZodType<T>
is my preferred way as it behaves better with Visual Studio Code, as seen in this StackOverflow post.Beta Was this translation helpful? Give feedback.
All reactions