Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spread operator incorrect type generation #1253

Open
2 tasks done
zane-atomus opened this issue Jul 26, 2024 · 0 comments
Open
2 tasks done

Spread operator incorrect type generation #1253

zane-atomus opened this issue Jul 26, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@zane-atomus
Copy link

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • 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 zane-atomus added the bug Something isn't working label Jul 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant