postgrest-js
postgrest-js copied to clipboard
Javascript RPC Typescript error: Argument of type 'string' is not assignable to parameter of type...
Bug report
- [ x] I confirm this is a bug with Supabase, not with my own application.
- [ x] I confirm I have searched the Docs, GitHub Discussions, and Discord.
Describe the bug
In the Javascript documentation an example is given for using rpc to call custom functions:
https://supabase.com/docs/reference/javascript/using-filters
const { data, error } = await supabase.rpc('hello_world')
In typescript, the following error is thrown:
Argument of type 'string' is not assignable to parameter of type 'never'.ts(2345)
To mitigate the error I had to add a custom typescript definition for the supabase client:
// supabaseCustom.d.ts
import { PostgrestBuilder } from '@supabase/postgrest-js';
import { SupabaseClient } from '@supabase/supabase-js';
declare module '@supabase/supabase-js' {
interface SupabaseClient {
rpc<ResponseType, ParamsType>(
fn: string,
params?: ParamsType
): PostgrestBuilder<ResponseType>;
}
}
To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
- attempt to use this code
const { data, error } = await supabase.rpc('hello_world')
Expected behavior
There should be no ts error
Hi, can you put up a repo so I can reproduce the issue? We have a test here which doesn't have the issue above, so not sure how that happens.
Experiencing the same issue using: "@supabase/auth-helpers-nextjs": "^0.7.4", "@supabase/auth-ui-shared": "^0.1.7", "@supabase/supabase-js": "^2.33.2",
Specifically, I'm using the createClientComponentClient from "@supabase/auth-helpers-nextjs"
@hichana ... I am no longer facing this issue. Make sure your generated types are up-to-date with the database. Generate with supabase gen types typescript --project-id abcdefghijklmnopqrst > database.types.ts
(or without --project-id
if local). This will create a hello_world
Function for you database.types.ts. I'm assuming you're initializing your supabase client with the Database type (ex. createClient<Database>(...)
. This is what's causing that error since your database.types.ts is not up-to-date with the db.
I can confirm @abeisleem you provided correct solution, thank you!
Hi, I believe this issue can be closed. The solution provided by @abeisleem is working fine, thanks for confirming the fix @ajesuscode.
For me, I used the supabase website to generate the types Link: https://supabase.com/docs/guides/api/rest/generating-types