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-valibot does not provide types for returned schemas #2521

Closed
valerii15298 opened this issue Jun 16, 2024 · 5 comments
Closed
Labels
bug Something isn't working drizzle/valibot

Comments

@valerii15298
Copy link

What version of drizzle-orm are you using?

drizzle-orm 0.31.2

What version of drizzle-kit are you using?

drizzle-kit 0.22.7

Describe the Bug

I wanted to use drizzle-valibot package to create ready to use validation schemas from drizzle schema.
I use this code from the example:

import { pgTable, serial, text, timestamp } from "drizzle-orm/pg-core";
import { createInsertSchema } from "drizzle-valibot";
const users = pgTable("users", {
  id: serial("id").primaryKey(),
  name: text("name").notNull(),
  email: text("email").notNull(),
  role: text("role", { enum: ["admin", "user"] }).notNull(),
  createdAt: timestamp("created_at").notNull().defaultNow(),
});
// Schema for inserting a user - can be used to validate API requests
const insertUserSchema = createInsertSchema(users);

Expected behavior

insertUserSchema should be properly typed.
But instead I get this:
Screenshot 2024-06-16 at 16 33 02
Note that insertUserSchema has any type...

Environment & setup

Nodejs,
typescript 5.4.5
drizzle-valibot 0.2.0
drizzle-kit 0.22.7
drizzle-orm 0.31.2

@valerii15298 valerii15298 added the bug Something isn't working label Jun 16, 2024
@Leo-Bourbon
Copy link

I had the same bug, and did a little bit of investigation. It seems that this bug is caused by the changes introduced in the 0.31 release of Valibot, which restructured the code to make use of a new pipe() function : https://valibot.dev/guides/migrate-to-v0.31.0/. One of the consequences of that change is that when using a valibot version from 0.31 or above, when looking at the typings for the createInsertSchema function for example, you can see that the return type of ObjectSchema<...> returns an error as it is now expecting two arguments instead of one.
image

Reverting valibot version to ^0.30.0 fixes the error and thus the bug. This means that we need to adapt the drizzle-valibot typings to the new version of ObjectSchema if we want to support any valibot versions above 0.30.

@fendyk
Copy link

fendyk commented Aug 2, 2024

Any info/progress on this issue?

@bobbymannino
Copy link

it seems that the return type is being purposely set to 'any' as you can see by the code, is there a reason why so?

@fendyk
Copy link

fendyk commented Oct 24, 2024

Just an update for the devs: Valibot is already at v1.0.0-beta.1, so maybe skip 0.31.0+?

@AndriiSherman
Copy link
Member

This one was fixed in the latest drizzle-valibot@0.3.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/valibot
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants