drizzle-zod failing

the createInsertSchema function is throwing errors when being used with @hookform/resolvers/zod, it's weird
// Form component
...
const form = useForm<NewComputer>({
resolver: zodResolver(insertComputerSchema),
});
...
// Form component
...
const form = useForm<NewComputer>({
resolver: zodResolver(insertComputerSchema),
});
...
throws this
Argument of type 'ZodObject<{ id: ZodString; brand: ZodString; cores: ZodNumber; }, UnknownKeysParam, ZodTypeAny, { id: string; brand: string; cores: number; }, { ...; }>' is not assignable to parameter of type 'ZodType<any, any, any>'.
The types of 'refine(...)._def.typeName' are incompatible between these types.
Type 'Zod.ZodFirstPartyTypeKind.ZodEffects' is not assignable to type
Argument of type 'ZodObject<{ id: ZodString; brand: ZodString; cores: ZodNumber; }, UnknownKeysParam, ZodTypeAny, { id: string; brand: string; cores: number; }, { ...; }>' is not assignable to parameter of type 'ZodType<any, any, any>'.
The types of 'refine(...)._def.typeName' are incompatible between these types.
Type 'Zod.ZodFirstPartyTypeKind.ZodEffects' is not assignable to type
schema and insertSchema declarations
export const computers = mysqlTable("computers", {
id: varchar("id", { length: 36 }).notNull().primaryKey(),
brand: varchar("brand", { length: 256 }).notNull(),
cores: int("cores").notNull(),
});

// Schema for CRUD - used to validate API requests
export const insertComputerSchema = createInsertSchema(computers);
export const computers = mysqlTable("computers", {
id: varchar("id", { length: 36 }).notNull().primaryKey(),
brand: varchar("brand", { length: 256 }).notNull(),
cores: int("cores").notNull(),
});

// Schema for CRUD - used to validate API requests
export const insertComputerSchema = createInsertSchema(computers);
1 Reply
Liltripple_reid
Liltripple_reidOP15mo ago
what's even weirder is that I have another project using the same pattern but doesn't throw any errors
Want results from more Discord servers?
Add your server