Currently seeking assistance with a server action in my Next.js application. I am encountering a type error that I can't seem to identify the root cause of. This issue arises when there are three values being passed into db.insert
for orderProduct, and it consistently errors out on the first value regardless of the field.
File: create-order.tsx
products.map(async ({ productId, quantity, variantId }) => {
await db.insert(orderProduct).values({
productVariantId: variantId,
productId: productId,
quantity,
orderId: order[0].id,
})
})
Schema:
export const orderProduct = pgTable('order_product', {
id: serial('id').primaryKey(),
quantity: integer('quantity').notNull(),
productVariantId: serial('productVariantId')
.notNull()
.references(() => productVariants.id, { onDelete: 'cascade' }),
productId: serial('productId')
.notNull()
.references(() => products.id, { onDelete: 'cascade' }),
orderId: serial('orderId')
.notNull()
.references(() => orders.id, { onDelete: 'cascade' }),
})
Types:
import * as z from 'zod'
export const createOrderSchema = z.object({
total: z.number(),
status: z.string(),
paymentIntentId: z.string(),
products: z.array(
z.object({
quantity: z.number(),
productId: z.string(),
variantId: z.string(),
}),
),
})
Error Message:
No overload matches this call.
Overload 2 of 2, '(values: { quantity: number | SQL<unknown> | Placeholder<string, any>; id?: number | SQL<unknown> | Placeholder<string, any> | undefined; productId?: number | SQL<...> | Placeholder<...> | undefined; productVariantId?: number | ... 2 more ... | undefined; orderId?: number | ... 2 more ... | undefined; }[]): PgInsertBase<...>', gave the following error.
Object literal may only specify known properties, and 'productVariantId' does not exist in type '{ quantity: number | SQL<unknown> | Placeholder<string, any>; id?: number | SQL<unknown> | Placeholder<string, any> | undefined; productId?: number | SQL<...> | Placeholder<...> | undefined; productVariantId?: number | ... 2 more ... | undefined; orderId?: number | ... 2 more ... | undefined; }[]'.ts(2769)
I continue to receive this error even if I rearrange the values within my db.insert function.