Anyone know how to fix this typescript issue?

I'm trying to connect taskId to an existing task table but I'm getting an error that says: Type '{ connect: { id: string | undefined; }; }' is not assignable to type 'string'.ts(2322) It is a one to many relationship (many tasks on a list). const list = await createList(); //^^ this part creates a list via a transaction in a different file and returns the data const task = await prisma.$transaction( Array(10) .fill(null) .map((_, i) => { return prisma.task.create({ data: { taskName: "Some name" taskDescription: "some description" listId: { <-HERE IS THE ISSUE (red squiggly) connect: { id: list[i]?.id, }, }, ....more queries & brackets, etc...
4 Replies
Brendonovich
Brendonovich3y ago
I suspect listId is a scalar field used in some sort of list relation. In that case, you only need to pass the id value itself, not the whole connect: { id: .. } stuff. That's only applicable to relation fields. If you still want to use that then assign to the corresponding relation field rather than the scalar listId field.
jix74
jix74OP3y ago
@Brendonovich Here is the schema if you don't mind giving it another guess. model List { id String @id @default(cuid()) name String @unique tasks ListTask[] materials Materials[] createdAt DateTime @default(now()) updatedAt DateTime @updatedAt } model ListTask { id String @id @default(cuid()) taskName String taskDescription String list List @relation(fields: [listId], references: [id]) listId String }
Brendonovich
Brendonovich3y ago
Yeah it’s just as I thought haha, just change listId to list in query and u should be good
jix74
jix74OP3y ago
Wow such an easy fix. Thank you Brendon!!

Did you find this page helpful?