supabase / supabase-js

An isomorphic Javascript client for Supabase. Query your Supabase database, subscribe to realtime events, upload and download files, browse typescript examples, invoke postgres functions via rpc, invoke supabase edge functions, query pgvector.
https://supabase.com
MIT License
2.86k stars 220 forks source link

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

Open jmisilo opened 4 months ago

jmisilo commented 4 months ago

Bug report

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.

sethtjf commented 3 months ago

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

jmisilo commented 3 months ago

@sethtjf I suggest you to use zod for validation

Ruchita1010 commented 2 months ago

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.