Complicated recursive types for self-relations in prisma models...
Prisma documentation says that types only contain the model's scalar fields, but doesn't account for any relations, thus you must use GetPayload.
Prisma Model:
Default type produced:
Modified with GetPayload
which just means:
But children isn't recursive in this type ^^^ because it doesn't contain relations right?
Correct way?
Default type produced:
Modified with GetPayload
Recursive - Is this the right way?
3 Replies
I'm recursively mapping through my categories via:
And my function keeps getting the following typescript error
The error message says that you cannot assign a single element of your „Category“ to an field which is typed to be an array of this element
In your type definition of CategoryWithRelations you typed parent to be an array - which does not seem to match your prisma schema.
I managed to fix all my type errors by re-defining a new type with manually-created relational properties and just making those relational properties equal to an array or single instance of the type (rather than the default prisma type that only contains scalar fields). Then I used type assertion on the data I received back from my trpc fetch to this new type. I'm now getting an error that says the
...transform part of my function is undefined. Such a headache...