supabase / postgrest-js

Isomorphic JavaScript client for PostgREST.
https://supabase.com
MIT License
964 stars 128 forks source link

Incorrect types on SELECT when spreading related tables #482

Open masda70 opened 9 months ago

masda70 commented 9 months ago

Bug report

Describe the bug

Spreading related tables, as described in this article , are not properly typed.

const { data } = await supabase.from('films').select(`
    title,
    ...technical_specs (
      camera, laboratory, duration
    )
  `)
console.log(data)

yields ParserError<"Expected identifier at ...technical_specs (camera, laboratory, duration)

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Use the table definitions from https://supabase.com/blog/postgrest-11-prerelease
  2. Write the above code within a supabase client environment.
  3. Build the project

Expected behavior

The type should be {title: string, camera: string, laboratory: string, duration: string}[] | null

System information

nielsvanrijn commented 2 months ago

No update on this? @masda70 did you find a workaround or did you just use .returns<...>() ?

masda70 commented 1 month ago

@nielsvanrijn I ended up not using the spread operator. I did retry using it 2 months ago, but noticed no difference in behavior.

bnjmnt4n commented 1 month ago

This should be fixed in https://github.com/supabase/postgrest-js/pull/497, which was released just about 2 months ago. If you upgrade to the latest version, this should be working fine.