© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•11mo ago
Razil

Drizzle Schema and TS

Hello, I have a question around how are we expected to consume the types from the schema generated by
drizzle-kit pull
drizzle-kit pull
.

// schema.ts
export const user_points = pgTable(
  'user_points',
  {
    user_id: uuid().primaryKey().notNull(),
    // You can use { mode: "bigint" } if numbers are exceeding js number limitations
    current: bigint({ mode: 'number' }).default(0).notNull(),
    // You can use { mode: "bigint" } if numbers are exceeding js number limitations
    spent: bigint({ mode: 'number' }).default(0).notNull(),
    // You can use { mode: "bigint" } if numbers are exceeding js number limitations
    total: bigint({ mode: 'number' }).default(0).notNull(),
    updated_at: timestamp({ withTimezone: true, mode: 'string' }).defaultNow(),
    created_at: timestamp({ withTimezone: true, mode: 'string' }).defaultNow(),
  },
  (table) => [
    foreignKey({
      columns: [table.user_id],
      foreignColumns: [users.id],
      name: 'user_points_user_id_fkey',
    }).onDelete('cascade'),
    check('user_points_current_check', sql`current >= 0`),
    check('user_points_spent_check', sql`spent >= 0`),
    check('user_points_total_check', sql`total >= 0`),
  ],
);
// schema.ts
export const user_points = pgTable(
  'user_points',
  {
    user_id: uuid().primaryKey().notNull(),
    // You can use { mode: "bigint" } if numbers are exceeding js number limitations
    current: bigint({ mode: 'number' }).default(0).notNull(),
    // You can use { mode: "bigint" } if numbers are exceeding js number limitations
    spent: bigint({ mode: 'number' }).default(0).notNull(),
    // You can use { mode: "bigint" } if numbers are exceeding js number limitations
    total: bigint({ mode: 'number' }).default(0).notNull(),
    updated_at: timestamp({ withTimezone: true, mode: 'string' }).defaultNow(),
    created_at: timestamp({ withTimezone: true, mode: 'string' }).defaultNow(),
  },
  (table) => [
    foreignKey({
      columns: [table.user_id],
      foreignColumns: [users.id],
      name: 'user_points_user_id_fkey',
    }).onDelete('cascade'),
    check('user_points_current_check', sql`current >= 0`),
    check('user_points_spent_check', sql`spent >= 0`),
    check('user_points_total_check', sql`total >= 0`),
  ],
);



then on the service if we want run an
update
update
operation:
import { user_points } from '@/src/drizzle/schema';

// ✅ this will work 
const [updated] = await db
      .update(user_points)
      .set({
        [user_points.current.name]: newCurrent,
        [user_points.spent.name]: newSpent,
        [user_points.updated_at.name]: new Date(),
      })
      .where(eq(user_points.user_id, userId))
      .returning();


// 💢 but used as:
const [updated] = await db
      .update(user_points)
      .set({
        current: newCurrent,
        spent: newSpent,
        updated_at: new Date(),
      })
      .where(eq(user_points.user_id, userId))
      .returning();

// will fail to infer the other columns and only `user_id` relation will be inferred
Object literal may only specify known properties, and 'current' does not exist in type '{ user_id?: string | SQL<unknown> | PgColumn<ColumnBaseConfig<ColumnDataType, string>, {}, {}>; }'.ts(2353)
import { user_points } from '@/src/drizzle/schema';

// ✅ this will work 
const [updated] = await db
      .update(user_points)
      .set({
        [user_points.current.name]: newCurrent,
        [user_points.spent.name]: newSpent,
        [user_points.updated_at.name]: new Date(),
      })
      .where(eq(user_points.user_id, userId))
      .returning();


// 💢 but used as:
const [updated] = await db
      .update(user_points)
      .set({
        current: newCurrent,
        spent: newSpent,
        updated_at: new Date(),
      })
      .where(eq(user_points.user_id, userId))
      .returning();

// will fail to infer the other columns and only `user_id` relation will be inferred
Object literal may only specify known properties, and 'current' does not exist in type '{ user_id?: string | SQL<unknown> | PgColumn<ColumnBaseConfig<ColumnDataType, string>, {}, {}>; }'.ts(2353)

Why is that? How we should correctly use it?

Thanks in advance 🙂
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Drizzle-Kit: incorrect schema.ts being used
Drizzle TeamDTDrizzle Team / help
3y ago
Drizzle-kit introspect:pg returned malformed schema.ts file
Drizzle TeamDTDrizzle Team / help
3y ago
Drizzle folder schema
Drizzle TeamDTDrizzle Team / help
16mo ago
Drizzle Schema Defaults
Drizzle TeamDTDrizzle Team / help
3y ago