drizzle-team / drizzle-team/drizzle-orm

[BUG]: Invalid type inference when using helpers

Open
#3,860 2 comments 2 reactions 0 assignees View on GitHub
bug monorepo priority
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
```
image
image

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.