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

Wrong response type for referenced table data when using the .single() modifier #512

Open
2 tasks done
hexrw opened this issue Dec 18, 2023 · 2 comments
Open
2 tasks done
Labels
bug Something isn't working

Comments

@hexrw
Copy link

hexrw commented Dec 18, 2023

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

Referenced tables (docs) are not typed correctly when used with .single(). The types don't match with the actual response.

May possibly actually be an issue with the underlying PostREST library, can't say for sure. confirmed

To Reproduce

create table
  countries (id int8 primary key, name text);
create table
  cities (
    id int8 primary key,
    country_id int8 not null references countries,
    name text
  );

insert into
  countries (id, name)
values
  (1, 'Germany'),
  (2, 'Indonesia');
insert into
  cities (id, country_id, name)
values
  (1, 2, 'Bali'),
  (2, 1, 'Munich');
const { data } = await supabase
  .from('countries')
  .select(`
    name,
    cities (
      name
    )
  `)
  .eq('name', 'Germany')
  .limit(1)
  .single()

Expected behavior

NOTE: To reduce the scope of where the issue originates from, I am not passing any types to the client instance. thus any is present

// Response
{
  "data": {
    "name": "Germany",
    "cities": {
      "name": "Munich"
    }
  }
}

// Type of `.data`
{
    name: any;
    cities: {
        name: any;
    };
}

Actual behavior

// Response
{
  "data": {
    "name": "Germany",
    "cities": {
      "name": "Munich"
    }
  }
}

// Type of `.data`
{
    name: any;
    cities: {
        name: any;
    }[];
}

(TS2339) | Property name does not exist on type { name: any; }[].

System information

  • OS: Ubuntu 22.04
  • Browser: Firefox (120)
  • Build tool: Vite
  • Server: Vite dev server, Vite preview server (prod build), Vercel
  • Version of supabase-js: 2.39.0

Additional context

Using this inside a Vue 3 (Composition API) application with Vite and TypeScript. The client is initialized the recommended way, as in the demos on GitHub that the official docs link to.

@hexrw hexrw added the bug Something isn't working label Dec 18, 2023
@steve-chavez steve-chavez transferred this issue from supabase/supabase-js Dec 18, 2023
@hexrw hexrw changed the title Type issue when using .single() for read queries with referenced tables Type issue when retrieving a single row using limit(1).single() referencing tables with one-to-one relationships Dec 27, 2023
@DhenPadilla
Copy link

Thanks for opening this @hexrw - This is also what I'm running into;

Any update to this supabase team?

@hexrw hexrw changed the title Type issue when retrieving a single row using limit(1).single() referencing tables with one-to-one relationships Wrong response type for referenced table data when using the .single() modifier May 9, 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

2 participants