Issue with JSON + TypScript

Here's my code:
.findFirst({ where: eq(globalBans.offender.id, userID) });
.findFirst({ where: eq(globalBans.offender.id, userID) });
Here's my schema:
interface GlobalBanUser {
id: string;
username: string;
avatar: string;
};

export const globalBans = pgTable("global_bans", {
offender: json("offender").notNull().$type<GlobalBanUser>(),
reason: text("reason").notNull(),
evidence: json("evidence").notNull().$type<string[]>(),
moderator: json("moderator").notNull().$type<GlobalBanUser>(),
notes: text("notes").notNull(),
date: timestamp("date", { mode: "date" }).defaultNow()
});
interface GlobalBanUser {
id: string;
username: string;
avatar: string;
};

export const globalBans = pgTable("global_bans", {
offender: json("offender").notNull().$type<GlobalBanUser>(),
reason: text("reason").notNull(),
evidence: json("evidence").notNull().$type<string[]>(),
moderator: json("moderator").notNull().$type<GlobalBanUser>(),
notes: text("notes").notNull(),
date: timestamp("date", { mode: "date" }).defaultNow()
});
Here's my error:
Property 'id' does not exist on type 'PgColumn<{ name: "offender"; tableName: "global_bans"; dataType: "json"; columnType: "PgJson"; data: GlobalBanUser; driverParam: unknown; notNull: true; hasDefault: false; enumValues: undefined; baseColumn: never; }, {}, {}>'.
Property 'id' does not exist on type 'PgColumn<{ name: "offender"; tableName: "global_bans"; dataType: "json"; columnType: "PgJson"; data: GlobalBanUser; driverParam: unknown; notNull: true; hasDefault: false; enumValues: undefined; baseColumn: never; }, {}, {}>'.
1 Reply
Ben-ificient
Ben-ificient8mo ago
You didn't explicitly define your id column so it wonn't exist in your interface
Want results from more Discord servers?
Add your server