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

`@supabase/supabase-js` TypeScript types - on join query

Open jmisilo opened this issue 1 year ago • 3 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

Types generated for TypeScript, based on the query content are not correct:

Query

const result = await dbServerClient
      .from('table_1')
      .select(
        'processed, created_at, table_2:table_2_id (name, table_3:table_3_id (name, image))',
      )
      .eq('id', id)

Provided type

PostgrestSingleResponse<{
    processed: any;
    created_at: any;
    table_2: {
        name: any;
        table_3: {
            name: any;
            image: any;
        }[];
    }[];
}[]>

Type in reality

PostgrestSingleResponse<{
    processed: string;
    created_at: string;
    table_2: {
        name: string;
        table_3: {
            name: string;
            image: string;
        };
    };
}[]>

Additional context

In theory difference is small, but it makes big types issues, since casting is required to make it work correctly.

jmisilo avatar Jan 08 '24 13:01 jmisilo

A fix for this would be greatly appreciated. Without this I'm still writing out types manually.

sethtjf avatar Feb 09 '24 15:02 sethtjf

@sethtjf I suggest you to use zod for validation

jmisilo avatar Feb 09 '24 16:02 jmisilo

Ah! I spent quite some time looking for a solution to this in the docs and elsewhere on the internet. I guess overriding the type is the only way for now.

Ruchita1010 avatar Mar 03 '24 16:03 Ruchita1010