© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•7mo ago•
1 reply
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)
.returns(MyType)
- this worked well.

Now, after an update,
.returns
.returns
no longer works and
.overrideTypes
.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>()
 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";
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>>()
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
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?
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,729Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Is using range on RPC recommended?
SupabaseSSupabase / help-and-questions
7mo ago
Typescript return type for Functions
SupabaseSSupabase / help-and-questions
4y ago
Supabase RPC functions return type shows a 2D array?
SupabaseSSupabase / help-and-questions
4y ago
Securing Helper Functions in RPC
SupabaseSSupabase / help-and-questions
4d ago