supabase / postgrest-js

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

Spread operator causes Typescript ParserError #459

Closed KrisBraun closed 4 months ago

KrisBraun commented 10 months ago

Bug report

Describe the bug

Using the new PostgREST spread operator works, but leads to a Typescript error:

error TS2339: Property 'invitees' does not exist on type 'ParserError<"Expected identifier at...contact(id,name,email,contact_user_id))">

To Reproduce

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

  1. Add spread (...) to a select().
  2. Compile with tsc

Expected behavior

Types should successfully be generated when queries include the spread operator.

System information

nathantew14 commented 8 months ago

I am facing the same issue. Although it works, the typescript is all fked up. Is there any workaround besides forcing the type?

destinio commented 7 months ago

Getting the same

Property 'number' does not exist on type 'ParserError<"Expected identifier at `...chapters(title, number) \n  `">'.ts(2339)

Version

    "@supabase/auth-helpers-nextjs": "^0.8.7",
    "@supabase/supabase-js": "^2.38.4",
import { Database } from '@/supabase'
import { createServerComponentClient } from '@supabase/auth-helpers-nextjs'
import { cookies } from 'next/headers'
import Link from 'next/link'

export default async function UserPage() {
  const supabase = createServerComponentClient<Database>({ cookies })

  const { data, error } = await supabase.from('favorites').select(`
    id, ...chapters(title, number) 
  `)

  if (!data) {
    return <h2>No chapters</h2>
  }

  return (
    <>
      <div className='m-auto max-w-4xl'>
        <h3>favorites</h3>
        <div className='flex flex-col'>
          {data.map(f => {
            return (
              <Link href={`/chapters/${String(f.number)}`} key={f.id}>
                {f.title}
              </Link>
            )
          })}
        </div>
      </div>
    </>
  )
}
arepp23 commented 5 months ago

Same issue here. Any way to force the type?

Aero56 commented 5 months ago

Same issue here. Any way to force the type?

@arepp23 You can make a custom type and pass it .single<Type>(); or .returns<Type[]>();

github-actions[bot] commented 4 months ago

:tada: This issue has been resolved in version 1.12.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: