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]: Expected to return type string but got type Date instead in runtime when using drizzle-orm/vercel-postgres #2019

Closed
philldev opened this issue Mar 16, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@philldev
Copy link

What version of drizzle-orm are you using?

0.30.1

What version of drizzle-kit are you using?

0.30.1

Describe the Bug

`
import { pgTable, date, uuid, boolean, varchar } from "drizzle-orm/pg-core";
import { subdistrictTable, villageTable } from "./regions";
import { userTable } from "./users";

export const scoutTable = pgTable("scouts", {
id: uuid("id").defaultRandom().primaryKey().notNull(),
fullname: varchar("fullname", {
length: 100,
}).notNull(),
dateOfBirth: date("date_of_birth").notNull(),
});

export type Scout = typeof scoutTable.$inferSelect; // return type when queried
export type NewScout = typeof scoutTable.$inferInsert; // insert type
`

when I created the table above and using vercel-postgres the typescript compiler got the dateOfbirth type correct which is string, but in runtime when I query the data from table above I got Date type instead of string that breaks React rendering.

Expected behavior

Expected to have string type in runtime instead of type date

Environment & setup

here is the DB client below
`
import { drizzle } from "drizzle-orm/vercel-postgres";
import { sql } from "@vercel/postgres";

const db = drizzle(sql);

export default db;
`

using nextjs "14.1.3" and vercel postgres database.

@philldev philldev added the bug Something isn't working label Mar 16, 2024
@sanghanihimanshu
Copy link

sanghanihimanshu commented Mar 16, 2024

export type Scout = typeof scoutTable.$inferSelect; // return type when queried
export type NewScout = typeof scoutTable.$inferInsert; // insert type

Can you explain this?

If you are exporting type then you can try scoutTable as type

@philldev
Copy link
Author

export type Scout = typeof scoutTable.$inferSelect; // return type when queried
export type NewScout = typeof scoutTable.$inferInsert; // insert type

Can you explain this?

If you are exporting type then you can try scoutTable as type

But the date type from the $inferSelect & $inferInsert is of type "string" not "Date" which is what i expected, but when i log the value in runtime i got "Date" type instead of "string"

@realmikesolo
Copy link
Collaborator

Hello, @philldev @sanghanihimanshu. This bug should be fixed in drizzle-orm@0.30.7.

https://github.com/drizzle-team/drizzle-orm/releases/tag/0.30.7

Also duplicate: 2058

@realmikesolo
Copy link
Collaborator

I close the issue because this bug was fixed

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

3 participants