ZodObject not inferred when using ZodSchema
See original GitHub issueI’m trying to extend a ZodObject
schema which is bound to an existing interface with ZodSchema
, however the schema is detected as ZodType
which does not have the extend()
method.
Is there some way to specify that the ZodSchema
is specifically a ZodObject
?
const ActiveServiceModel: ZodSchema<ActiveService> = z.object({
service_id: z.string(),
team_id: z.string().uuid()
})
// This fails:
const ExtendedActiveServiceModel = ActiveServiceModel.extend({
bar: z.string()
})
Error Detail
TS2339: Property 'extend' does not exist on type 'ZodType '.
(ActiveServiceModel: z.ZodType<ActiveService, z.ZodTypeDef, ActiveService>)
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (1 by maintainers)
Top Results From Across the Web
Typecheck schemas against existing types · Issue #372 - GitHub
I would love to have a way to ensure that a Zod schema matches an existing type definition using the normal Typescript type...
Read more >Schema validation in TypeScript with Zod - LogRocket Blog
In this article, you will learn about schema design and validation in Zod and how to run it in a TypeScript codebase at...
Read more >Why does Zod make all my schema fields optional?
This might be caused by not using strict: true in TypeScript compiler options as referred to installation section in README file.
Read more >TypeScript schema validation with Zod - Iskander Samatov
Zod is designed to be TypeScript-first, meaning that the library will automatically infer the static TypeScript type for your data structures.
Read more >Designing the perfect Typescript schema validation library
But it's very uncool for the inferred type to not actually reflect ... For instance, consider how to define an object schema with...
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
@JRGranell this is very cool:
thanks for that 🤙🏻
This seems like this question was answered. May I close this?