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

Incorrect types on SELECT when spreading related tables

Open masda70 opened this issue 2 years ago • 3 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

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

  • OS: [e.g. Ubuntu]
  • Version of supabase-js: 2.37.0
  • Version of Node.js: v18.17.1

masda70 avatar Oct 02 '23 08:10 masda70

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

nielsvanrijn avatar Apr 16 '24 21:04 nielsvanrijn

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

masda70 avatar Apr 30 '24 12:04 masda70

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.

bnjmnt4n avatar May 01 '24 08:05 bnjmnt4n