zod Questions
4
Solved
I am using Zod inside my Express & TypeScript & Mongoose API project and when trying to validate my user input against the user schema it returns types conflicts:
Argument of type '{ first...
Cordey asked 19/2, 2022 at 13:56
1
Solved
I have implemented a form to sign in using zod for client-side validation. I wanted to also add a password strength display for which i decided to try out react-password-strength-bar.
The functiona...
Admetus asked 18/11, 2023 at 14:6
3
I am in a bit of a weird situation. For the past 2 weeks I've been trying to debug as to why I am losing types between my projects inside a monorepo. My backend exposes the types that my client use...
Northwest asked 24/10, 2022 at 18:14
5
Solved
When defining a schema with zod, how do I use a date type?
If I use z.date() (see below) the date object is serialized to a ISO date string. But then if I try to parse it back with zod, the validat...
Anterior asked 18/1, 2023 at 9:47
2
Solved
I created a customer registration form, but all my "messages" from my "errors" are coming as required. Does anyone know what it could be? Something I set up wrong in zod or reac...
Masochism asked 12/7, 2023 at 15:44
3
I am trying to add validation for a form that has a checkbox selection with a number input next to each checkbox. A user selects a profession checkbox and then enters the number of years of experie...
Orthopedics asked 31/12, 2022 at 4:38
1
Solved
I have a schema and I need to make it so that the role field is only validated when the value of the subject field is 1, otherwise the role should not be validated at all
const schema = z.object({
...
Millihenry asked 5/8, 2023 at 16:31
2
Solved
I am trying to make an input that should take in a number between a certain range. When I submit it, zod says it expected a number but got a string.
import {z} from "zod"
import { fromZod...
Siberson asked 23/6, 2023 at 3:52
1
Solved
Say you have a basic system like this in Zod:
import { z } from 'zod'
const Post = z.object({
title: z.string(),
})
const User = z.object({
name: z.string(),
email: z.string().optional(),
pos...
Lubin asked 20/5, 2023 at 0:59
3
I have number or numeric string, I want transform it to number and continue validate it by .min() .max(), but it don't work as I expected
const numberValid = z.number().or(z.string().regex(/^\d+$/)...
Irradiance asked 9/2, 2022 at 16:1
2
Solved
I have implemented this code using JOI where the user has to send the userId and at least one of the keys from the body. How to implement the same using ZOD ??
params: Joi.object().keys({
userId:...
Skurnik asked 8/8, 2022 at 16:55
1
Solved
I got the Typescript error:
Property 'infer' does not exist on type 'typeof import(.../node_modules/zod/lib/external)
on the code:
const CampaignForm = z.infer<typeof CampaignSchema>;
Looking...
Pockmark asked 26/4, 2023 at 13:24
1
Solved
I have a Vite library using Zod. I want to parse configurations and my folder structure is similiar to the configuration object structure. index.ts files always export all files in their own direct...
Antalya asked 6/4, 2023 at 4:47
0
What is the recommended way of handling image uploads in a form that supports both adding and editing of a product? Here is my current implementation with two options, is there any suggestion to im...
Sundew asked 12/3, 2023 at 12:19
1
Solved
Imagine I have an object like
{
field1: 'test',
field2: 'test1'
}
How I can create the following validation:
If field1 and field2 both are empty - it is not valid
If field1 and field2 both...
Begotten asked 26/2, 2023 at 13:3
1
Solved
We can create Zod object that validates an object against the keys that are defined in the schema, but I only want to validate if the key is a string not if the key == something
In typescript we ca...
Disputable asked 7/2, 2023 at 13:19
1
I want to make a dynamic Form that show different input fields based on a Boolean value.
When calling useForm of the react-hook-form package I use a zod object to validate my inputs. This object is...
Blackford asked 27/10, 2022 at 9:8
1
Solved
I have an object with a numeric property. I'd like to make sure that the number has only up to 2 decimal digit.
e.g:
1 // good 1.1 // good 1.11 // good 1.111 //bad
Is there way to do that?
Looked a...
Felicity asked 30/1, 2023 at 13:37
1
Solved
I have the following object that is autogenerated
export const ReportDimensions = {
CHANNELS: 'CHANNELS',
DAY: 'DAY',
DOW: 'DOW',
MONTH: 'MONTH',
WEEK: 'WEEK'
} as const;
I would like to use ...
Troublesome asked 24/1, 2023 at 5:46
2
Solved
I do have an external URL endpoint that returns an array of field object when it is more than 2 and an object when there is only one, see the snippet below:
Return when the field count is one:
{
&...
Desperation asked 17/10, 2022 at 17:16
1
Solved
Validating a string can be done with a regex. That's easy.
const myString = z.string().regex(/A string/);
But what about other data types?
I guess the following could work for number, but it doesn...
Creswell asked 20/1, 2023 at 17:42
1
I have been using Zod validation library with typescript for a little while and been loving it.
This might be a very basic thing, but I am trying to figure out what would be best pattern to extend ...
Inadvertence asked 26/12, 2022 at 11:52
1
Solved
I've got this generic interface for paginated response:
export interface PaginatedResponse<T> {
pageIndex: number;
pageSize: number;
totalCount: number;
totalPages: number;
items: Array&...
Anthracite asked 24/12, 2022 at 12:5
1
Solved
I have the following discriminated union:
enum Option {
FULL = 'FULL',
TIME_PERIOD = 'TIME_PERIOD',
MONTH = 'MONTH',
}
const schema = z.discriminatedUnion('option', [
z.object({ option: z.lite...
Joselyn asked 13/12, 2022 at 20:32
1
Solved
I'm making a project with the TMDB API and trying to make it super type-safe to reinforce some of the TypeScript stuff I'm learning. I'm using Zod to describe the shape of the data returned by the ...
Cockcroft asked 7/12, 2022 at 19:8
© 2022 - 2025 — McMap. All rights reserved.