Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]:Drizzle-zod:Boolean and Serial types from Schema are defined as enum<unknown> when using CreateInsertSchema and CreateSelectSchema #1327

Closed
0xMazout opened this issue Oct 1, 2023 · 6 comments
Labels
bug Something isn't working drizzle/zod

Comments

@0xMazout
Copy link

0xMazout commented Oct 1, 2023

What version of drizzle-orm are you using?

0.28.6

What version of drizzle-kit are you using?

0.19.13

Describe the Bug

I've create a thread on Drizzle Discord in Help with details on it : https://discord.com/channels/1043890932593987624/1155846666780426280

With screenshots and explanation.

In resume : There is a problem for drizzle-zod. When you load Schema Boolean and Serial are recognize as unknown and it force you to override them and redefine them

Expected behavior

Don't need to override it and when you load schema using CreateInsertSchema and CreateSelectSchema. Boolean and Serial types are Boolean and numbers

Environment & setup

Using drizzle-zod in a Frontend app using vscode.

@0xMazout 0xMazout added the bug Something isn't working label Oct 1, 2023
@AkshayPathak
Copy link

I am also seeing this with decimal, integer, boolean and timestamp from drizzle-orm/pg-core. Even defining a $type does not seem to fix this.

@locohost
Copy link

Yeah this is killing me too on integer fields. the createInsertSchema seems to wreck the type defs for any SQLite/LibSQL schemas. Question: Above you mention "override" them in the create..., I do know how to do this and have tried this but can't get this to fix anything. Can someone post how to overide this so the type comes out correct?...

loginfails: integer("loginfails", { mode: "number" }).notNull().default(0),

Without any create... override, I get this type error in my repo code...

image

Why that type error on the loginfails integer field? Am I doing something stupid?

@yadav-saurabh
Copy link

I am also seeing this with decimal, integer, boolean and timestamp from drizzle-orm/pg-core. Even defining a $type does not seem to fix this.

facing the same

@Haffi921
Copy link

Haffi921 commented Jul 27, 2024

I am getting a similar error with SQLite, although I don't know if it is related...

integer and numeric from drizzle-orm/sqlite-core are being interpreted as ZodEnum<undefined>

Here's a screenshot:
image

Additionally, name in this example is interpreted as ZodOptional, even though it's marked as notNull

OS: Windows 10
Drizzle-ORM Version 0.32.0
Drizzle-Zod Version 0.5.1

===============================

EDIT: I just fixed my issue with "strictNullChecks": true in tsconfig.json (see Zod Issue 121)

@thedewpoint
Copy link

@Haffi921 thanks so much for replying here, I was at my wits end trying to figure out why it worked in one of my projects but not my other one. I wasted about 3 hours on this. The post you linked solved my problem as well.

@AndriiSherman
Copy link
Member

This one was fixed in the latest drizzle-zod@0.6.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working drizzle/zod
Projects
None yet
Development

No branches or pull requests

8 participants