supabase / postgrest-js

Isomorphic JavaScript client for PostgREST.
https://supabase.com
MIT License
1.04k stars 133 forks source link

[Bug] `from` returns any type #356

Closed bastiaanv closed 1 year ago

bastiaanv commented 1 year ago

Bug report

Using the new supabase-js, the from function always returns the any type, while I have the Database interface given during initialisation.

To Reproduce

Database.ts

export type Json =
  | string
  | number
  | boolean
  | null
  | { [key: string]: Json }
  | Json[]

export interface Database {
  public: {
    Tables: {
      themes: {
        Row: {
          id: string
          name: string
          color: string
          image: string
        }
        Insert: {
          id?: string
          name: string
          color: string
          image: string
        }
        Update: {
          id?: string
          name?: string
          color?: string
          image?: string
        }
      }
    },
    Views: {
      [_ in never]: never
    }
    Functions: {
      [_ in never]: never
    }
    Enums: {
      [_ in never]: never
    }
  }
}

function.ts

export function supabaseClient() {
  return createClient<Database>(environment.supabase.url, environment.supabase.key, {
    auth: {
      autoRefreshToken: true,
      persistSession: true,
    },
  });
}

supabase.from('themes').select('name,colors(*),images(*)').order('id').limit(1).single()

Return message on from:

(method) SupabaseClient<Database, "public", { Tables: { themes: { Row: { id: string; name: string; color: string; image: string; }; Insert: { id?: string | undefined; name: string; color: string; image: string; }; Update: { ...; }; }; }; Views: {}; Functions: {}; Enums: {}; }>.from<"themes", {
    Row: {
        id: string;
        name: string;
        color: string;
        image: string;
    };
    Insert: {
        id?: string | undefined;
        name: string;
        color: string;
        image: string;
    };
    Update: {
        id?: string | undefined;
        name?: string | undefined;
        color?: string | undefined;
        image?: string | undefined;
    };
}>(relation: "themes"): any (+2 overloads)

Expected behavior

I would expect from to return PostgrestQueryBuilder<{ id: string; name: string; color: string; image: string; }> (or something like that) to continue type safety

System information

soedirgo commented 1 year ago

Can you try updating @supabase/supabase-js? This might be related to https://github.com/supabase/supabase-js/issues/602 which we recently fixed

bastiaanv commented 1 year ago

It is. Thank you!