drizzle-team / drizzle-team/drizzle-orm
[BUG]: unknown type for coerced fields in drizzle-zod in zod 4
- 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.45.2
### What version of `drizzle-kit` are you using?
--
### Other packages
"drizzle-zod": "0.8.3"
### Describe the Bug
```
export const { createInsertSchema, createSelectSchema, createUpdateSchema } =
createSchemaFactory({
coerce: { date: true, number: true },
});
```
when using coerce true with zod 4 , number and and date become of type unknown in schema.
because in zod 4
[z.coerce updates](https://zod.dev/v4/changelog?id=zcoerce-updates)
The input type of all z.coerce schemas is now unknown.
const schema = z.coerce.string();
type schemaInput = z.input;
// Zod 3: string;
// Zod 4: unknown;
the solution to this is :
This is a common TypeScript issue with Zod v4: by default, z.coerce.number() expects an input of unknown, which causes type inference problems with form resolvers like react-hook-form. The fix is to specify the input type generic, for example: z.coerce.number() if your input is a string (which is typical for HTML form fields). This will make the inferred type for credit a number as expected and resolve the type error in your resolver
please fix the return type in the right files.
Contributor guide
Assessment
This issue has not been assessed yet.