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]: Invalid type inference when using helpers #3860

Open
1 task done
777advait opened this issue Dec 28, 2024 · 0 comments
Open
1 task done

[BUG]: Invalid type inference when using helpers #3860

777advait opened this issue Dec 28, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@777advait
Copy link

777advait commented Dec 28, 2024

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.38.3

What version of drizzle-kit are you using?

^0.30.1

Other packages

No response

Describe the Bug

im using helpers for primaryKey and current timestamp
column.helper.ts
im using helpers for primaryKey and current timestamp
column.helper.ts

import { integer, text } from "drizzle-orm/sqlite-core";

export const primaryKey = () =>
  text()
    .primaryKey()
    .$defaultFn(() => crypto.randomUUID());

export const timestamp = () =>
  integer({ mode: "timestamp" }).default(new Date()).notNull();

schema.ts

import { primaryKey, timestamp } from "@align/db/helpers/column.helper";
import { sqliteTable, text } from "drizzle-orm/sqlite-core";

export const waitlistMember = sqliteTable("waitlist_members", {
  id: primaryKey(),
  name: text().notNull(),
  email: text().unique().notNull(),
  joined_at: timestamp(),
});

i exported the types from my packages/db which has correct types. however the query i return, returns type any for the fields where i used the helpers. if i switch back to normally typing the column type instead of a helper it gives correct types

export const waitlistMember = sqliteTable("waitlist_members", {
  id: text().primaryKey().$defaultFn(() => crypto.randomUUID()),
  ...
});
// ^^^^ this returns type `string` when results of query is returned

export const waitlistMember = sqliteTable("waitlist_members", {
  id: primaryKey(),
  name: text().notNull(),
  email: text().unique().notNull(),
  joined_at: timestamp(),
});
// ^^^^ this returns type `any` when results of query is returned
image image
@777advait 777advait added the bug Something isn't working label Dec 28, 2024
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

1 participant