-
-
Notifications
You must be signed in to change notification settings - Fork 414
Description
Feature request - Option for nulls as undefined
Currently, all empty values returned by the API are set as null
.
The difference between null
and undefined
for many (obviously not all) TypeScript devs is meaningless, leading many to drop the null
type completely. (In current projects I go as far as enforcing the Microsoft no-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 all nulls
to undefined
.
b) A server-side option to send (edit: #244 (comment))null
values as undefined
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:
import { z } from "zod"
export const FooSchema = z.object({
id: z.number().optional(),
title: z.string(),
color: z.string().optional().default("red")
})
const { data, error } = await supabase.from(`foos`).select(`id, title, color`).single()
if (data) {
const foo = FooSchema.parse(foo)
}
ZodError.ts:134 Uncaught (in promise) ZodError: [
{
"code": "invalid_type",
"expected": "string",
"received": "null",
"path": [
"color"
],
"message": "Expected string, received null"
}
]
Normally this would convert an empty value for "color"
to "red"
, however due to the fact that null !== undefined
it fails.