supabase / postgrest-js

Isomorphic JavaScript client for PostgREST.
https://supabase.com
MIT License
965 stars 129 forks source link

Unexpected type for foreign table query? #406

Open probablykasper opened 1 year ago

probablykasper commented 1 year ago

Bug report

Describe the bug

When doing a foreign table query, for some reason the type is T | T[] | null.

To Reproduce

With the following code

    const { data, error } = await supabaseClient
        .from('pages')
        .select(`*, profiles ( id )`)
        .eq('name', event.params.page)

        if (data) {
            const { profiles, ...page } = data[0]
        }

I get this type shown when I hover over the profiles variable:

const profiles: {
    id: string;
} | {
    id: string;
}[] | null

Expected behavior

If supabase-js doesn't have enough information to tell how many results the foreign query can give, I'd expect the type to only be T[].

If supabase-js does know that only 0-1 records can be returned, then I'd expect the type to only be T | null.

System information