-
-
Notifications
You must be signed in to change notification settings - Fork 138
Return types for RPC cannot have nullable properties #841
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
Comments
One thing that changing this will likely do is affect a lot of people's code. (i.e. types that were previously non-null are now suddenly going to throw a lot of typescript compile errors) So it may be wise to have this behind some sort of feature flag, i.e. |
here's my workaround: type PartialNullBy<T, E extends keyof T> = {[K in keyof T]: K extends E ? (T[K] | null) : T[K]}
type PartialBy<T, K extends keyof T> = Omit<T, K> & Pick<Partial<T>, K>
type ArrayElement<ArrayType extends readonly unknown[]> = ArrayType extends readonly (infer ElementType)[] ? ElementType : never
type Debug<T> = T extends Function ? T : {[K in keyof T]: T[K]} use the let {data} = await locals.supabase.rpc("get_bananas")
let better = data as Array<PartialNullBy<ArrayElement<typeof data>, "current_status" | "another_column_if_you_want">> now, the resultant type will look gross, but you can wrap the whole thing with |
Same issue here. There is a stackoverflow question which suggests a solution using a reference to the table type. https://stackoverflow.com/questions/77427669/supabase-rpc-typescript-types-nullable Is that still a working solution @dshukertjr ? I was not able to make that solution work. A simpler test example: table definition:
postgres function:
generated types:
It is also a bit strange that the args object includes The correct type would be identical to the row type:
compare generated table row type:
windows 11 docker desktop |
The
supabase gen types
appears to lack support for RPC functions returning objects with nullable properties.Steps to reproduce:
Define an RPC function:
Run the command:
Examine the generated types:
It doesn't seem possible to make
current_status
nullable out of the box, even though it can be missing.Workaround
Extend the generated types from another file to overwrite properties.
The text was updated successfully, but these errors were encountered: