postgrest-js icon indicating copy to clipboard operation
postgrest-js copied to clipboard

Javascript RPC Typescript error: Argument of type 'string' is not assignable to parameter of type...

Open hichana opened this issue 1 year ago • 5 comments

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:

  1. attempt to use this code const { data, error } = await supabase.rpc('hello_world')

Expected behavior

There should be no ts error

hichana avatar Apr 15 '23 09:04 hichana

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.

soedirgo avatar Apr 19 '23 03:04 soedirgo

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"

abeisleem avatar Sep 27 '23 18:09 abeisleem

@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.

abeisleem avatar Sep 28 '23 08:09 abeisleem

I can confirm @abeisleem you provided correct solution, thank you!

ajesuscode avatar Jan 10 '24 23:01 ajesuscode

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

Screenshot_3300

zillBoy avatar Jun 23 '24 05:06 zillBoy