strictUndefinedChecks undesired behavior
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:
In this schema, ipv4
is optional. However, when I use a header that might be undefined
, like so:
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.3 Replies
You selected the carefully hand-crafted route. A dev artisan will respond soon. Meanwhile, the
#ask-ai
channel awaits if you're curious!Can you try using Prisma.Skip?
The Prisma.skip symbol can be used to explicitly omit the field from the query if it is undefined.
I think this is a little annoying having to do this every time though no? This does fix the issue, but having to remember to do this everytime we update or create a value that is potentially undefined is a bit cumbersome?
this doesn't really address the full problem of the
findFirst
. Before this new preview feature came into effect we'd have to remember to check if the field we were querying by was undefined or not, we seemlying still need to remember to do this for every potentially undefined field?
Just going back to the original post,
If undefined values are indeed disallowed, wouldn’t it be helpful if the types only accepted aI think this would be a major improvement, and it wouldn't require us to remember to use Prisma.skip everytime we use an undefined field? I think the current implementation of this will just introduce more bugs because we get no intellisense from typescript saying that this could potentially cause an error due to prisma not allowing undefined valuesstring
ornull
instead? This way, any potential issues could be caught during development instead of at runtime.