supabase-js icon indicating copy to clipboard operation
supabase-js copied to clipboard

Spread operator incorrect type generation

Open zane-atomus opened this issue 1 year ago • 0 comments

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:

  1. Create a table parent with an id column as the primary key.
  2. Create a table (child) with a foreign key relationship to parent (id) (we'll call this column parent_id), and a constraint unique (parent_id). For the example we will add two columns col_1, col_2 which have type boolean and are not null.
  3. Run a query with supabase-js with the spread operator const { 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

zane-atomus avatar Jul 26 '24 18:07 zane-atomus