drizzle-team / drizzle-team/drizzle-orm
[BUG]: Drizzle-Zod "expected a Zod schema"
- Dominant language
- TypeScript
- Stars
- 35.8k
- Forks
- 1.6k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 4
Description
### Report hasn't been filed before.
- [x] I have verified that the bug I'm about to report hasn't been filed before.
### What version of `drizzle-orm` are you using?
0.44.4
### What version of `drizzle-kit` are you using?
0.31.4
### Other packages
drizzle-zod@0.8.2 zod@3.24.3
### Describe the Bug
When using a schema created from `drizzle-zod`, such as `createUpdateSchema`, `createInsertSchema`, or `createSelectSchema`, the second accepted parameter gives Type errors for any schema created with Zod. Additionally, an error message shows at runtime stating `Invalid element at key "{key}": expected a Zod schema`.
Here's some code to replicate
```
import { z } from "zod";
const schema = createUpdateSchema(schema.product, {
// TypeError below: Type 'ZodOptional' is not assignable to type 'ZodType> | ((schema: ZodNumber) => ZodType>) | undefined'.
price: z.coerce.number().optional() // I would expect this to be an acceptable type, as the documentation says.
//price: z.number().optional() // I have even tried this, I get the same exact result.
});
// --> Runtime would fail here upon invocation!!!
const result = schema.safeParse({
price: "1.23"
});
```
I may be doing something wrong, and I accept that if that is the case, but regardless, the error handling here does not help me in the slightest bit. I followed the documentation exactly as stated, yet I get type errors. If I choose to ignore the type errors, I just get hit with runtime errors claiming what I gave isn't a valid zod schema, when it CLEARLY is.
I am using this as a way to validate a form submission in SvelteKit, and SvelteKit sends form data as all strings, so I need to coerce some of these values to numbers. I've tried many different methods to fix this, and all of them result in type or runtime errors.
This is also true for the other `createSchema` functions.
Contributor guide
Assessment
This issue has not been assessed yet.