Open roker15 opened 1 year ago
I also have this issue. For example:
const result = await supabaseClient
.from('Orders')
.select(`
order_id,
Customers (
name,
customer_id
)`)
.eq('Customers.customer_id, 10);
result
has the return type
PostgrestResponse<{
order_status: number;
id: number;
created_at: string | null;
customer_id: number;
} & {
Customers: unknown;
}>
when I would expect the return type to be:
PostgrestResponse<{
order_status: number;
id: number;
created_at: string | null;
customer_id: number;
} & {
Customers: {
name: string,
customer_id: number
}
}>
Where the type of Customers properties should be determined from the Database schema.
This bug means that result.Customers.name
is not possible due to "Customers" being unknown type, instead it must be done something like:
type Customer = Database['public']['Tables']['Customers']['Row'];
const customerName = (result.Customers as Customer).name;
Which is not ideal, as this approach will allow properties from the db missed from the query (e.g. if the table has a "email" field in customers table, but we forgot to include it in the query, (result.Customers as Customer).email
would compile with TypeScript but throw an error at runtime).
I can second this.
Even forcing on the from the type it does not work as <"table", Type> it works on the first one but always fails on relations.
Here is Example link from supabase docs.
In above example
countries.name
shows error in types. And no autocompletion available aftercountries.