supabase-js
supabase-js copied to clipboard
Spread operator incorrect type generation
Bug report
- [x] I confirm this is a bug with Supabase, not with my own application.
- [x] I confirm I have searched the Docs, GitHub Discussions, and Discord.
Describe the bug
When joining a related one-to-one table using the ... spread operator, the type generation assumes that the rows exist in the related table and does not have null as an option for the child table column values, however the returned data has null values for rows where the row is missing.
To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
- Create a table
parentwith anidcolumn as the primary key. - Create a table (child) with a foreign key relationship to
parent (id)(we'll call this columnparent_id), and a constraintunique (parent_id). For the example we will add two columnscol_1,col_2which have typebooleanand arenot null. - Run a query with
supabase-jswith the spread operatorconst { data, error } = db.from("parent").select("id,...child(col_1,col_2).
Expected behavior
Since the child row might not exist for a given parent row, the type of data should be:
{
id: string;
col_1: boolean | null;
col_2: boolean | null;
}
instead it gives:
{
id: string;
col_1: boolean;
col_2: boolean;
}
The returned data contains null values as expected which makes the typing inaccurate.
System information
- OS: macOS
- Version of supabase-js: 2.44.1
- Version of Node.js: 20.12.1