SupabaseS
Supabase5mo ago
Felix

Recommended pattern for Return Types on RPC functions

Hi there,

I have some rpc's that return JSON for use in my frontend. Previously, I had their corresponding return types declared in my typescript and used .returns(MyType)
  • this worked well.
ow, after an update, .returns no longer works and .overrideTypes is the new way. However, I can not get this to work with the existing RPC's:

 const { data } = await supabaseClient
    .rpc('get_personal_account')
    .single() // same issue without this line
    .overrideTypes<GetAccountResponse>()


leads to Error: "Type mismatch: Cannot cast array result to a single object. Use .overrideTypes<Array<YourType>> or .returns<Array<YourType>> (deprecated) for array results or .single() to convert the result to a single object";

With Array<>, I get a different error message:

const { data } = await supabaseClient
    .rpc('get_personal_account')
    .overrideTypes<Array<GetAccountResponse>>()


leads to Type mismatch: Cannot cast single object to array type. Remove Array wrapper from return type or make sure you are not using .single() up in the calling chain

To me, it looks like these error messages are conflicting. Is there something I'm overlooking? What is the recommended way to deal with RPC's returning JSON?
Was this page helpful?