drizzle-team / drizzle-team/drizzle-orm
[BUG]: Invalid type inference when using helpers
- Dominant language
- TypeScript
- Stars
- 35.8k
- Forks
- 1.6k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 4
Description
### Report hasn't been filed before.
- [X] 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`
```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
```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
```ts
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
```
Contributor guide
Assessment
This issue has not been assessed yet.