-
Notifications
You must be signed in to change notification settings - Fork 65
Null vs undefined for optional values #572
Comments
Thanks a lot for raising this issue @krzkaczor! Would you mind sharing some of your application code where you're interacting with the Prisma Client and where you'd prefer to use |
Building on top of https://github.com/prisma/prisma-examples/blob/prisma2/typescript/rest-express/src/index.ts
|
I'm also in for such change in the api. It makes a lot of sense when working with optional attributes, which can be undefined but not null. |
A well-known js dev weighs in: sindresorhus/meta#7 https://news.ycombinator.com/item?id=24956156 |
Thanks for the question! In the Prisma Client there's a specific difference between
prisma.user.create({
data: {
id: 10,
customer: null
}
} The row in an SQL database looks like this:
prisma.user.create({
data: {
id: 10,
customer: undefined
}
} Conceptually that's the same as prisma.user.create({
data: {
id: 10
}
} This leaves the prisma engine to decide the value, falling back on the
This conceptual difference doesn't show up that often in Javascript libraries, which is why Sindre chose to consolidate the concept. For Prisma, the difference matters. Hope this helps! |
What's the reasoning for using
null
for optional values in generated typings?I feel like lots of folks prefer to use only one type to determine the absence of a value and usually, they settle on
undefined
.Is it possible to customize this during generation?
The text was updated successfully, but these errors were encountered: