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

Unexpected type when querying referenced table with count #939

Open peperoli opened 4 months ago

peperoli commented 4 months ago

Bug report

Describe the bug

When querying a referenced table with count option like this:

const supabase = createClientComponentClient<Database>()

const { data } = supabase.from('concerts').select(`*, bands_count:j_concert_bands(count)`

count is returned correctly:

[
  {
    "id": 1,
    "bands_count": [
      {
        "count": 29
      }
    ]
  }
]

But when using the returned count value there's a type error:

data.forEach(item => {
  const count = item.bands_count[0].count
  // Property 'count' does not exist on type 'SelectQueryError<"Referencing missing column `count`">'.
}

Expected behavior

No error message because count does in fact exist.

System information

salvinoto commented 3 months ago

Im having same issue as well

peperoli commented 3 months ago

This issue is active in the postgrest-js repo: https://github.com/supabase/postgrest-js/issues/447