-
-
Notifications
You must be signed in to change notification settings - Fork 280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature Request] - Option for nulls as undefined #244
Comments
+1, I realized after the fact that e.g. the TypeScript coding guidelines (caveat: read the title) uses only Rather than making it a configuration though, I'd prefer to apply this for supabase-js v2 instead. What do you think? |
That sounds awesome. 😍 (ps: I always love reading that warning on the TS guidelines page, they must be so sick of this debate by now 🤣) |
One thing to note regarding JSON is that For instance, When stringifying a JavaScript object into JSON, all key/value-pairs with the value of Here's an example:
So, when retrieving data via Supabase (or Postgrest), we may get a whole lot of fields being We could of course use some recursive function to do this manually, but it would be nice if it would be baked in to the library via an options parameter. So, it's not just a question about TypeScript or schema validations, because it returns a completely different dataset in JSON depending on whether it's |
@danielpox thanks for the input! Yes, in supabase/postgrest-js#278 we decided to adopt the Prisma team's stance on this. We do use |
Hi all, while I also would love this feature from TypeScript / client side, it would also be awesome if the payload sent by the backend could be stripped of null values. Rows / queries which return a lot of nulls often include way more key/value pairs (where the value is |
With each passing day, I'm coming back to this issue, wondering if this is the reason that zod in trpc output is failing. Am I correct to assume that supabase now returns undefined for null? and that the typegen in cli doesn't account for this by generating return types as well? While the response may be typed, I am using supabase-to-zod and then using the zod result in trpc output validation. |
The author describes the implementation as "hacky" and the last release was a year ago. I'd be careful in building on it in general. But I think the idea of it is superb. |
The idea of anything zod is repulsive to me. Unfortunately I was not behind that decision. zod was put in to use tRPC, and then supabase-to-zod to generate zod validators. I am a NestJS type of gentleman myself. Class-validator rules. |
Also running into this, and its an absolute pain. Im building forms that have optional fields, and in typescript, that pretty simple with -
but constantly running into supabase problems with it complaining that I cannot assign I think this would be relatively easy to coerce using something like -
but would be awesome if this could be a config in the lib as mentioned above :) |
Feature request - Option for nulls as undefined
Currently, all empty values returned by the API are set as
null
.The difference between
null
andundefined
for many (obviously not all) TypeScript devs is meaningless, leading many to drop thenull
type completely. (In current projects I go as far as enforcing the Microsoftno-new-null
eslint rule for example.)This isn't meant to trigger any debate over if that is "right or wrong", just that undeniably (and for whatever reasons) some developers have this particular preference for type simplification.
Describe the solution you'd like
a) A configuration option in the
SupbaseClient
that coerces allnulls
toundefined
.b) A server-side option to send(edit: #244 (comment))null
values asundefined
pre-flight.Describe alternatives you've considered
Presently I need to run each record through a recursive function to convert each
null
value and adjust the type shape accordingly.Additional context
A specific case where this is especially problematic:
Normally this would convert an empty value for
"color"
to"red"
, however due to the fact thatnull !== undefined
it fails.The text was updated successfully, but these errors were encountered: