drizzle-zod doesn't work with Array in pg

I'm using drizzle-orm, drizzle-kit & drizzle-zod in my application. One of my schema looks like following:
export const committee = pgTable("committee", {
id: text("id").primaryKey().notNull(),
safety_health: text("safety_health"),
safety_health_sources: text(
"safety_health_sources"
).array(),
// other properties
export const committee = pgTable("committee", {
id: text("id").primaryKey().notNull(),
safety_health: text("safety_health"),
safety_health_sources: text(
"safety_health_sources"
).array(),
// other properties
The schema works fine when I push, safety_health_sources is created as an array (No issues till this point) I create zod schema as well, like following:
export const committeeSchema = createSelectSchema(committee);
export const committeeSchema = createSelectSchema(committee);
and when I do:
type Committee = Partial<
z.infer<typeof committeeSchema>
>;
// the type become something like following
type Committee = {
id?: string | undefined;
safety_health?: string | null | undefined;
safety_health_sources?: string | null | undefined; // <--- The problem is here, it should be an Array<string>
// other properties
}
type Committee = Partial<
z.infer<typeof committeeSchema>
>;
// the type become something like following
type Committee = {
id?: string | undefined;
safety_health?: string | null | undefined;
safety_health_sources?: string | null | undefined; // <--- The problem is here, it should be an Array<string>
// other properties
}
4 Replies
BabaYaga
BabaYagaā€¢13mo ago
I'm using the latest version of everything:
"drizzle-orm": "^0.28.5",
"drizzle-zod": "^0.5.1",
"drizzle-kit": "^0.19.13"
"drizzle-orm": "^0.28.5",
"drizzle-zod": "^0.5.1",
"drizzle-kit": "^0.19.13"
rphlmr āš”
rphlmr āš”ā€¢13mo ago
Could you use that?:
type Committee = Partial<InferInsertModel<typeof committee>>;
type Committee = Partial<InferInsertModel<typeof committee>>;
šŸ‘‡
type Committee = {
id?: string | undefined;
safety_health?: string | null | undefined;
safety_health_sources?: string[] | null | undefined;
}
type Committee = {
id?: string | undefined;
safety_health?: string | null | undefined;
safety_health_sources?: string[] | null | undefined;
}
BabaYaga
BabaYagaā€¢13mo ago
This seems to work, Thanks šŸ«‚ But, can you tell me what is wrong in the process that I'm following?
rphlmr āš”
rphlmr āš”ā€¢13mo ago
Seems fine at first but it is better with drizzle type helper that has some infer rules
Want results from more Discord servers?
Add your server