Schemas generated by refine do not have the omit method (or that is what typescript says)
See original GitHub issueHello, first of all, thanks for Zod, it’s fantastic. According to typescript, the objects that have been refined do not have the omit method. To reproduce you can try something as simple as this
const schema = z.object({ name: z.string(), age: z.number() }).refine(() => true);
const newSchema = schema.omit({ name: true }) // <- omit does not exist
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:5
Top Results From Across the Web
Untitled
What is Zod Zod is a TypeScript-first schema declaration and validation library. ... Currently there is no support for Date or bigint literals...
Read more >Why does Zod make all my schema fields optional?
I am using Zod inside my Express & TypeScript ...
Read more >TypeScript schema validation with Zod - Iskander Samatov
Documentation: A good schema validation library will provide accurate type definitions for the data structures you use. Type definitions can be ...
Read more >Documentation - Narrowing - TypeScript
Argument of type 'string | number' is not assignable to parameter of type ... of the function in a truthy check, but this...
Read more >The Seven Sources of Unsoundness in TypeScript
The static types may or may not have anything to do with real ... Another is to generate JSON Schema from your TypeScript...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Is this a bug or expected behavior? If it is the latter, can it we changed?
Yeah, I know this seems not optimal, but it keeps everything explicit in a way that arbitrarily adding effects on defined schemas did not. There is a whole long history and context here: https://github.com/colinhacks/zod/issues/264 but here’s a bit of a snippet of the issue we’re trying to avoid:
and
Also consider this:
Obviously the object methods wouldn’t make sense here, but if you had a chain of different transform, you suddenly have to keep track of when they become object-like or array-like or promise-like or primitive-like, etc.
My personal recommendation is to separate out the input validation logic from any “effects” as a matter of principle when writing schemas. You can still just export the logical schemas most of the time, but in cases where you need to extend and apply effects to those schemas, either write a new schema in that same module, or export the base schema and effects to reassemble however you need.