Giter Club home page Giter Club logo

Comments (8)

chanthinh avatar chanthinh commented on September 21, 2024 1

@dstoyanoff, yah I know, glad to help you

from zod.

JacobWeisenburger avatar JacobWeisenburger commented on September 21, 2024 1

and change strict to false

I highly recommend that you don't do this. This will cause other problems and so strict should always be used for Zod.


This does seem to be a bug, however, I think that deepPartial is in process of being deprecated. So I'm not sure this will be fixed, but I could be wrong.

from zod.

dstoyanoff avatar dstoyanoff commented on September 21, 2024 1

and change strict to false

I highly recommend that you don't do this. This will cause other problems and so strict should always be used for Zod.


This does seem to be a bug, however, I think that deepPartial is in process of being deprecated. So I'm not sure this will be fixed, but I could be wrong.

I see that it's getting deprecated, but at the moment there is no suggested alternative in the docs. Happy for an alternative solution to deepPartial.

from zod.

chanthinh avatar chanthinh commented on September 21, 2024

Hi @dstoyanoff,
You mean:

import { z } from 'zod';

const user = z.object({
  username: z.string().superRefine((value) => value.length >= 1),
  location: z.object({
    latitude: z.number(),
    longitude: z.number(),
  }),
  strings: z.array(z.object({ value: z.string() })),
});

const deepPartialUser = user.deepPartial();

type AAA = z.infer<typeof deepPartialUser>;

from zod.

dstoyanoff avatar dstoyanoff commented on September 21, 2024

Hello @chanthinh, its more like this:

import { z } from 'zod';

const user = z.object({
  username: z.string(),
  location: z.object({
    latitude: z.number(),
    longitude: z.number(),
  }).superRefine(() => false),
  strings: z.array(z.object({ value: z.string() })),
});

const deepPartialUser = user.deepPartial();

type AAA = z.infer<typeof deepPartialUser>;

here is a codesandbox - https://codesandbox.io/p/devbox/polished-rain-738nnl?file=%2Fsrc%2Findex.ts%3A23%2C1

from zod.

chanthinh avatar chanthinh commented on September 21, 2024

@dstoyanoff,
You can check this one:
https://stackblitz.com/edit/typescript-zgzrzk?file=schemas%2FschemaWithDefaultType.ts

and change strict to false

Hope this help you

{
  "include": ["./src/*"],
  "compilerOptions": {
    "esModuleInterop": true,
    "strict": false
  }
}

from zod.

dstoyanoff avatar dstoyanoff commented on September 21, 2024

Thanks @chanthinh, but Zod itself recommends that strict is enabled, so this change is rather controversial.

from zod.

tsdineshjai avatar tsdineshjai commented on September 21, 2024

Hi @dstoyanoff, You mean:

import { z } from 'zod';

const user = z.object({
  username: z.string().superRefine((value) => value.length >= 1),
  location: z.object({
    latitude: z.number(),
    longitude: z.number(),
  }),
  strings: z.array(z.object({ value: z.string() })),
});

const deepPartialUser = user.deepPartial();

type AAA = z.infer<typeof deepPartialUser>;

@chanthinh "refine" method suffices for custom validation, just want to know why superRefine is used in this case, which is better for customizing error codes.

from zod.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.