hey,
I am really happy to see the new preview feature strictUndefinedChecks . However, I did run into some confusion testing.
When using it I notice that errors are thrown during create and update operations, specifically when an undefined value is used in the data object of the query.
Using the following schema as an example:
model TrpcQueries {
id Int @id @default(autoincrement())
correlationId String
path String
duration Int
userId String?
ipv4 String?
createdAt DateTime @default(now())
User User? @relation(fields: [userId], references: [id])
@@index([userId])
@@index([correlationId])
}
In this schema, ipv4 is optional. However, when I use a header that might be undefined, like so:
await prisma.trpcQueries.create({
data: {
correlationId: "id...",
path: "path",
duration: 123,
ipv4: ctx.headers?.get('x-forwarded-for'),
},
});
I was wondering why an undefined value isn’t allowed here. If undefined values are indeed disallowed, wouldn’t it be helpful if the types only accepted a string or null instead? This way, any potential issues could be caught during development instead of at runtime.