supabase / postgrest-js

Isomorphic JavaScript client for PostgREST.

Home Page:https://supabase.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unexpected type for foreign table query?

probablykasper opened this issue · comments

commented

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

  • OS: macOS
  • Version of supabase-js: 2.8.0
  • Version of Node.js: 18.13.0