-
-
Notifications
You must be signed in to change notification settings - Fork 140
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
ParserError "Unexpected input: .sum()" when using aggregate functions with TypeScript #523
Comments
Moving this issue to Postgrest-js repo. Issue is similar to #447 which was fixed recently |
A brief update after upgrading Error in TypeScript type is now as following for the same original code: const data: SelectQueryError<"Referencing missing column `sum`">[] | null Using @bnjmnt4n I just had a look into your fix for the similar issue with |
@bnjmnt4n I added test cases which currently fail at compile-time. |
@stefan-girlich thanks for providing the examples; I'm really busy now so I can probably look at them next week only. |
In case it helps anyone, here's a generic way to override the faulty type: import fail from '@/utils/fail'
import { createClient } from '@/utils/supabase/server'
type FixSupabaseAggregateType<
T extends readonly any[] | null,
K extends keyof R,
R extends Record<K, any>,
> = Array<Omit<NonNullable<T>[number], K> & R>
export const fetchSomeData = async () => {
const supabase = createClient()
const { data, error } = await supabase
.from('some_table')
.select(
`
some_prop,
other_table(aggregated_prop:nested_prop.sum())
`
)
if (error) fail(error)
type Result = FixSupabaseAggregateType<
typeof data,
'other_table',
{
other_table: { aggregated_prop: number }
}
>
return data as unknown as Result
} @bnjmnt4n Would you know if a fix is scheduled already? Thanks! |
@bnjmnt4n Would you know more? I can look into a solution/PR myself, but I'd be happy about some guidance concerning how to tackle this. |
Is this resolved? Facing the same issue here. |
@sanjaybaskaran01 dont think it has been resolved, im also seeing the same when trying to use |
The fix has been released in |
Hi @avallete, Thanks for the update! I was excited to upgrade to const { data, error } = await supabase
.schema('not_public')
.from('my_table')
.select('seller, ...sellers(code)')
.match({ region });
if (error) throw error; The inferred
I'm writing this here because I have a feeling this issue is related to the fix of aggregate functions (if not, happy to create a new issue for this). Thanks |
Hey @cohlar do you think you could submit a request trough the supabase support, or if it isn't sensitive provide those infos for debugging:
That way we can reproduce on our end and get this fixed. |
I created a case with supabase support ✅ |
This now seems fixed on version |
Hey @we-ink Sadly the fixes did some unexpected breaking changes on some codebases. That's the reason why we reverted in 2.46.1 and we are currently considering it as a breaking change and releasing it following the release candidate procedure to let people the time to migrate. Please try the And if you have any issues, please let us know by following the recommended procedure so we can debug and fix it 👍 |
Bug report
Describe the bug
When I use aggregate functions, the inferred TypeScript data type will always depict an error, requiring me to use casts to
any
.To Reproduce
The inferred type for
data
seen in my VS Code is:ParserError<"Unexpected input: .sum(),\n ...other_things(id, name, color)\n ">[] | null
Inference works fine when not using aggregate functions.
Re-generating TS types via
supabase gen types typescript
does not fix the issue.Expected behavior
Types should be inferred correctly without an error.
System information
The text was updated successfully, but these errors were encountered: