© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•8mo ago•
3 replies
xhudaman

Types don't infer correctly for tables with`references` method?

I'm using Drizzle with Expo SQLite in an Expo managed app. On my schema all of the tables that contain simple column data, i.e. primitive types like
text
text
or
int
int
, get typed correctly. Any time I create an association with the
references
references
method the generated type becomes
{ [x: string]: any }
{ [x: string]: any }
.

I'm using:
- Expo SDK: 51
- Expo SQLite: 14.0.6
- drizzle-orm: 0.44.2
- drizzle-kit: 0.31.1

I'll give an example directly from my schema.

In my schema I have the table
movementTypes
movementTypes
and a join table that connects it with another table called
characters
characters
.

// schema.ts
export const movementTypes = sqliteTable('movementTypes', {
  id: int().primaryKey({ autoIncrement: true }),
  name: text().notNull(),
  label: text().notNull()
});

// Generated type for movementTypes as returned via InferSelectModel<typeof movementTypes>
// {
//   id: number;
//   name: string;
//   label: string;
// }

export const characterMovementTypes = sqliteTable('characterMovementTypes', {
  id: int().primaryKey({ autoIncrement: true }),
  movementTypeId: int()
    .notNull()
    .references(() => movementTypes.id),
  characterId: int()
    .notNull()
    .references(() => characters.id),
  speed: int().notNull()
});

// Generated type for movementTypes as returned via InferSelectModel<typeof characterMovementTypes>
// { [x: string]: any }
// schema.ts
export const movementTypes = sqliteTable('movementTypes', {
  id: int().primaryKey({ autoIncrement: true }),
  name: text().notNull(),
  label: text().notNull()
});

// Generated type for movementTypes as returned via InferSelectModel<typeof movementTypes>
// {
//   id: number;
//   name: string;
//   label: string;
// }

export const characterMovementTypes = sqliteTable('characterMovementTypes', {
  id: int().primaryKey({ autoIncrement: true }),
  movementTypeId: int()
    .notNull()
    .references(() => movementTypes.id),
  characterId: int()
    .notNull()
    .references(() => characters.id),
  speed: int().notNull()
});

// Generated type for movementTypes as returned via InferSelectModel<typeof characterMovementTypes>
// { [x: string]: any }


Even if I try to specify the type of the column with the
$type<>()
$type<>()
method, I'm still not getting the correct type returned for the table's model.

Is there a way to get this to generate correctly? I'd be happy with a solution that requires passing types as args or generated by the drizzle api.

Thanks in advance for any help!
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

Data types for tables
Drizzle TeamDTDrizzle Team / help
3y ago
Randomly losing types for tables.
Drizzle TeamDTDrizzle Team / help
6mo ago
Two tables that references each other
Drizzle TeamDTDrizzle Team / help
2y ago
Unable to infer relationship between tables
Drizzle TeamDTDrizzle Team / help
2y ago