Some tables aren't typed (type any)

For example heres one table:
export const orgTheme = pgTable("OrgTheme", {
id: text().primaryKey().notNull(),
orgId: text().notNull(),
name: text(),
backgroundImageUrl: text(),
primaryColorLight: text().notNull(),
primaryColorDark: text().notNull(),
createdAt: timestamp({ precision: 3, mode: 'date' }).default(sql`CURRENT_TIMESTAMP`).notNull(),
updatedAt: timestamp({ precision: 3, mode: 'date' }).notNull(),
deletedAt: timestamp({ precision: 3, mode: 'date' }),
}, (table) => [
index("OrgTheme_deletedAt_idx").using("btree", table.deletedAt.asc().nullsLast().op("timestamp_ops")),
uniqueIndex("OrgTheme_id_key").using("btree", table.id.asc().nullsLast().op("text_ops")),
foreignKey({
columns: [table.orgId],
foreignColumns: [org.id],
name: "OrgTheme_orgId_fkey"
}).onUpdate("cascade").onDelete("cascade"),
]);
export const orgTheme = pgTable("OrgTheme", {
id: text().primaryKey().notNull(),
orgId: text().notNull(),
name: text(),
backgroundImageUrl: text(),
primaryColorLight: text().notNull(),
primaryColorDark: text().notNull(),
createdAt: timestamp({ precision: 3, mode: 'date' }).default(sql`CURRENT_TIMESTAMP`).notNull(),
updatedAt: timestamp({ precision: 3, mode: 'date' }).notNull(),
deletedAt: timestamp({ precision: 3, mode: 'date' }),
}, (table) => [
index("OrgTheme_deletedAt_idx").using("btree", table.deletedAt.asc().nullsLast().op("timestamp_ops")),
uniqueIndex("OrgTheme_id_key").using("btree", table.id.asc().nullsLast().op("text_ops")),
foreignKey({
columns: [table.orgId],
foreignColumns: [org.id],
name: "OrgTheme_orgId_fkey"
}).onUpdate("cascade").onDelete("cascade"),
]);
orgTheme is type any, but most of my other tables have types. Anyone know whats wrong? when i remove the table function it works fine
15 Replies
JustWayne
JustWayne•3mo ago
No description
JustWayne
JustWayne•3mo ago
I got a type for it, but as you can see I'm missing your org table. Maybe your org table is at fault with a circular dependency circular import
<@235148962103951360>
<@235148962103951360>OP•3mo ago
the org table also is typed any they are all in the same file. its been introspected
JustWayne
JustWayne•3mo ago
you can try to restart your typescript language server or just restart your vs code instance
<@235148962103951360>
<@235148962103951360>OP•3mo ago
i still get type any after doing that
JustWayne
JustWayne•3mo ago
i guess you'll need to show more code then for anyone to help you the code you gave here worked
<@235148962103951360>
<@235148962103951360>OP•3mo ago
if i remove all the foreign keys, it works fine
JustWayne
JustWayne•3mo ago
then something might be in the wrong order, e.g. using a table before it's declared and somehow eslint/ts not catching that? idk there might be a betterw ay to define a foreign key though for you' with a function because then it's late-bound
<@235148962103951360>
<@235148962103951360>OP•3mo ago
the order is possible. theres around 35 tables and lots of referencing org and other tables
JustWayne
JustWayne•3mo ago
All my foreign keys are defined like this: project_id: text().references(() => projects.id),
<@235148962103951360>
<@235148962103951360>OP•3mo ago
ill try adding that to the tables
JustWayne
JustWayne•3mo ago
You can set the options too
created_by: text().references((): AnyPgColumn => users.id, {
onDelete: "set null",
onUpdate: "set null"
}),
created_by: text().references((): AnyPgColumn => users.id, {
onDelete: "set null",
onUpdate: "set null"
}),
Oh also, see that type I used there? For some reason I had to do that at some point but I might be able to undo it now idk why I had that wide type there for AnyPgColumn (but that same thing might help to untangle the type inference problems) (btw I added the onUpdate to show u that, it's not my code)
<@235148962103951360>
<@235148962103951360>OP•3mo ago
hmm ill try that thanks wow that worked thanks!! much appreciated @JustWayne 💯 seems introspect doesnt generate the fks properly
<@235148962103951360>
<@235148962103951360>OP•3mo ago
https://github.com/drizzle-team/drizzle-orm/issues/2993 this seems like it might be the same issue but there wasnt a solution in it
GitHub
[BUG]: unclear how to correctly define mutual foreign keys (introsp...
What version of drizzle-orm are you using? 0.33.0 What version of drizzle-kit are you using? 0.24.2 Describe the Bug Defining tables with foreign keys to each other causes drizzle-kit to output sch...
JustWayne
JustWayne•3mo ago
Niccceee!

Did you find this page helpful?