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]: using .omit on schemas created with createInsertSchema throws an error #4016

Open
1 task done
Rick-Phoenix opened this issue Jan 27, 2025 · 4 comments
Open
1 task done
Labels
bug Something isn't working

Comments

@Rick-Phoenix
Copy link

Report hasn't been filed before.

  • 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.39.0

What version of drizzle-kit are you using?

0.30.3

Other packages

drizzle-zod 0.7.0

Describe the Bug

What is the undesired behavior?

  • Using .omit on a schema generated with drizzle-zod's createInsertSchema creates the following error: "Type 'true' is not assignable to type 'never'." for each of the fields being omitted. Using .extend, on the other hand, works as expected.

What database engine are you using? Are you using a specific cloud provider? Which one?

  • Postgres

Are you working in a monorepo?

  • Yes

Other notes:

  • Using .omit on a createSelectSchema works fine, as do other methods like .pick or .extend on both select and insert schemas. Only using .omit on an insert schema creates this problem.
  • Using node with typescript 5.7.2
  • First had this problem when using drizzle-kit 0.30.2 and drizzle-orm 0.38.3, after updating to drizzle-zod 0.7.0. Updated the former two to the new versions and the problem persisted.
  • The issue was not present when using drizzle-zod 0.5.1.
@Rick-Phoenix Rick-Phoenix added the bug Something isn't working label Jan 27, 2025
@Rick-Phoenix
Copy link
Author

Can confirm after going back to drizzle-zod 0.5.1 fixes the issue while keeping drizzle-kit and drizzle-orm to their new versions (0.30.3 and 0.39.0, respectively), so the issue is probably related to that package.

@timur-khakhalev
Copy link

the same for me, the code from this example https://orm.drizzle.team/docs/zod#refinements doesn't work too. I've tried this:

export const UsersInsertValidationSchema = createInsertSchema(users, {
  id: schema => schema.id.optional(),
  createdAt: schema => schema.createdAt.optional(),
  updatedAt: schema => schema.updatedAt.optional(),
})
Type '(schema: any) => any' is not assignable to type 'DrizzleTypeError<"Found unknown key in refinement: \"createdAt\"">'.ts(2322)
users.ts(34, 3): The expected type comes from property 'createdAt' which is declared here on type 'NoUnknownKeys<{ id: (schema: any) => any; createdAt: (schema: any) => any; updatedAt: (schema: any) => any; }, {}>'

@timur-khakhalev
Copy link

@Rick-Phoenix hey! Do you have "strict": true in your tsconfig.json? Because this fixed for me

@Rick-Phoenix
Copy link
Author

Yep I do

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

No branches or pull requests

2 participants