Invalid type inference when using helpers

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();
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(),
});
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
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
No description
No description
1 Reply
TOSL
TOSL2mo ago
I feel like your code is fine and it shouldn't be showing an any for the type of any of those object keys. I'm assuming you've updated TS to the latest and restarted you language server and editor? And made sure editor is actually using the latest

Did you find this page helpful?