Ryan Westlake
04/20/2022, 9:42 PMJson
fields defined in my models. For example:
model Template {
pages Json @default("[]")
}
An example of a page is:
{
title: string; // e.g. 'blah'
}
Because we cannot add specific types to Json
fields for postgres yet, when I start looping through pages
all of the keys throw a typescript error like the image below. It is a Prisma.JsonValue
instead of a string
. This forces me to put the values in a variable and cast them as the correct type whenever I want to reference them. As you can expect, that litters the code base with casts and is certainly not what I want.
Maybe I’m missing something… how are folks dealing with this?Casey Chow
04/21/2022, 1:18 AMRyan Westlake
04/21/2022, 4:21 PM@prisma/client
types?Casey Chow
04/21/2022, 4:33 PM