Comments (8)
@dstoyanoff, yah I know, glad to help you
from zod.
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.
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.
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.
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.
@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.
Thanks @chanthinh, but Zod itself recommends that strict is enabled, so this change is rather controversial.
from zod.
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)
- Incorrect type derivation when using z.array() with z.transform() HOT 2
- question: How can I show fielderrors as hints?
- zod import triggers an error in typescript HOT 2
- Module '"zod"' has no exported member 'z'.ts HOT 9
- Add nonempty() method to zod.record() for empty object validation
- parsed data is becoming never HOT 10
- Idea: `.meta(...)` method on ZodType HOT 1
- How to union or merge two or more z.record schemas HOT 1
- Type narrowing not working with generic zod type HOT 1
- Allow `.extract`/`.exclude` for `nativeEnum`s
- Update repo link `zod-accelerator` in readme.
- feat: Adding json Schema to the package
- Question: TypeScript Isolated Declarations
- Problem with validation of identical fields in the schema HOT 4
- Although `z.string().date()` check fails, yet the callback to `.superRefine()` is executed.
- Bug: .safeParse() should not throw
- values of type number are not accepted when key of NativeEnum is specified as a number type HOT 1
- The mapped-type is not recursive in `ZodFormattedError` (`error.format()`)
- Access, manipulate, and throw error from `z.catch` HOT 3
- Bug: z.output makes all properties optional HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zod.