Issue with JSON + TypScript
Here's my code:
Here's my schema:
Here's my error:
.findFirst({ where: eq(globalBans.offender.id, userID) });
.findFirst({ where: eq(globalBans.offender.id, userID) });
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()
});
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
You didn't explicitly define your
id
column so it wonn't exist in your interface