Damian M
03/16/2022, 8:17 AMctx.prisma[`${var)Model`].upsert(....
Typescript automatically creates a union with the variable possiblities but as these models have different fields I get an error like
Each member of the union type '(<T extends .... ..... => CheckSelect<...>)' has signatures, but none of those signatures are compatible with each other.
Is there anyway to fix this problem?millsp
03/30/2022, 8:08 AMupsert
), then TypeScript (for safety) will only allow you to access the intersection of those. This is to prevent you accessing things that could potentially not exist or be incompatible across members of the union. In this case, the methods signatures are incompatible.millsp
03/30/2022, 8:09 AMfunction autoUpsert1(model: 'user' | 'link') {
const prisma = new PrismaClient()
if (model === 'link') {
return prisma[model].upsert({})
}
if (model === 'user') {
return prisma[model].upsert({})
}
}
⢠You go into unsafe mode with any
function autoUpsert2(model: 'user' | 'link') {
const prisma = new PrismaClient()
return (prisma[model] as any).upsert({})
}
millsp
03/30/2022, 8:11 AM