drizzle-team / drizzle-team/drizzle-orm
[BUG]: drizzle-zod when using coerce: true maps `float` as `int` and vice versa
- 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.
### Other packages
drizzle-zod 0.8.2
### Describe the Bug
```ts
const test = pgTable("test", {
float: doublePrecision(),
});
const { createSelectSchema } = createSchemaFactory({
coerce: true,
});
const schema = createSelectSchema(test);
schema.parse({ float: 5.5 }); // error thrown here
```
In this case `float` field in `schema` will be `integer` because of wrong ternary operator here:
https://github.com/drizzle-team/drizzle-orm/blob/main/drizzle-zod/src/column.ts#L244
```ts
integer ? z.coerce.number() : z.coerce.number().int()
```
Number field is returned when column type is int and vice versa(int returned when actual type is float)
Contributor guide
Assessment
This issue has not been assessed yet.