Questions tagged [zod]

A JavaScript/TypeScript library for TypeScript-first schema validation with static type inference.

A JavaScript/TypeScript library for TypeScript-first schema validation with static type inference.

https://zod.dev/

332 questions
0
votes
0 answers

How to define the type of object's key using same object's another key in TypeScript?

Consider following pseudo type signature for TypeScript: import { z, ZodObject, ZodRawShape } from 'zod'; export type DefinitionObject = { validator: ZodObject; htmlFn: (value: z.infer & { locale?:…
Harshal Patil
  • 17,838
  • 14
  • 60
  • 126
0
votes
1 answer

TypeScript error when using Remix action inferred types

;tldr Has anyone successfully used zod for server side validation in Remix while using the new(ish) type inference for the action function? const actionData = useActionData(). I can get it to work when I am only handling a single…
SThomas
  • 15
  • 6
0
votes
1 answer

How to map the field names of a Zod Discriminated Union

Given a discriminated union export const duParser = z.discriminatedUnion('type', [ z.object({ type: z.literal('a'), id: aParser, }), z.object({ type: z.literal('b'), id: bParser, }), ]); z.infer would be {type: 'a', id: A} |…
Igor Loskutov
  • 2,157
  • 2
  • 20
  • 33
0
votes
0 answers

Infer method argument from another property

I'm trying to infer a zod schema of another property to be used as a argument type in a method. (Zod is a typescript-first validation library that lets you infer types based on the zod schema object using the z.infer util -…
doctorwho
  • 1
  • 1
0
votes
0 answers

How to create conditional types in typescript?

So I have a Form component in react which takes props to handle various different situations. As I am using it for an online store it will mostly be sending input data to the server, and it needs to work with zod and infered tRPC typings. and I made…
0
votes
0 answers

Zod schema validation. TypeError: Cannot read properties of undefined

TypeError: Cannot read properties of undefined (reading 'extend'). The path to Base import is correct. Typescript sees extend field on Base schema. base.policy.ts import * as z from "zod"; const Base = z.object({ one: z.any(); two:…
pi88a
  • 81
  • 7
0
votes
1 answer

Can't z.infer<> in a generic typescript parameter when schema contains a union type?

So I'm trying to make a helper that will allow me to easily create empty/initial form values from a zod schema that will validate the whole/complete form. In other words I want the schema to require every field to be populated, but initial values…
morgs32
  • 1,439
  • 3
  • 17
  • 26
0
votes
1 answer

UseMemo cant read value from zod validation?

Need help,i used zod to validate my data and try to used function useMemo when i cursor to the value as in image the value can read from zod validation but when i put the value the error come out as image. I tried to put index to the value also…
nur alliffah
  • 21
  • 1
  • 2
0
votes
1 answer

Validate with ZOD

I'm trying to use zod validator, with typeorm. I saw few tutorials how to use zod. and i write little code but, it does not work it's saying "message": "payloadSchema.safeParse is not a function". am trying to validate product store method. export…
BasDriver
  • 171
  • 3
  • 9
0
votes
1 answer

Doubts about type inference when using pick of zodObject

when calling the pick method of a zodObject in a function by passing in a reference, how to set the type of T to ensure the correct type of return value? function zodPickDemo>(src: T) { return src.pick({ id: true…
fu xiao
  • 13
  • 3
0
votes
1 answer

zod-prisma keeps getting stuck at the generation step

I just installed zod-prisma to try it out, but so far nothing is working. I attempted to run it on two separate projects, one has a small prisma and the other has a relatively large one. Both didn't work, and remained stuck. I can't share the…
Omar Dulaimi
  • 846
  • 10
  • 30
0
votes
1 answer

How to transform a recursive generic's shape (typescript)

I love the Zod parser but I may have gotten in over my head creating a form lib. In the ideal end state, the input shape is transformed to create { fieldA: { value, onChange, errors } }. It works for a single level, but it's not clear how to support…
exrhizo
  • 141
  • 2
  • 13
0
votes
3 answers

Create string object path from array of index/keys

I'm using Zod to validate the input of my application forms and when a validation error happens I receive an array of errors with a message property and a path property. I need to transform the received path property to a string object path so I can…
Alfonso
  • 1,125
  • 1
  • 13
  • 23
-1
votes
1 answer

Defined Value Giving: Object is possibly 'undefined'`. How to Avoid Manually Re-Asserting Types Using Zod

In this function, I am getting a type error from VS Code. The error refers to board[0]. The error states Object is possibly 'undefined' which refers to` export default function validPosition(board: Grid | Board, position: Position) { const [row,…
currenthandle
  • 1,038
  • 2
  • 17
  • 34
-2
votes
1 answer

Typings in vscode, how to show the whole type

It will be great to have an option to expend the hover canvas when you want to see the whole type.
1 2 3
21
22