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

ParserError "Unexpected input: .sum()" when using aggregate functions with TypeScript #523

Open
2 tasks done
stefan-girlich opened this issue Mar 11, 2024 · 4 comments
Open
2 tasks done
Labels
bug Something isn't working

Comments

@stefan-girlich
Copy link

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

When I use aggregate functions, the inferred TypeScript data type will always depict an error, requiring me to use casts to any.

To Reproduce

  const { data } = await supabase.from("things").select(`
    field.sum(),
    ...other_things(id, name, color)
  `);

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

  • OS: MacOS
  • Version of supabase-js: 2.39.7
  • Version of Node.js: 21.6.2
@stefan-girlich stefan-girlich added the bug Something isn't working label Mar 11, 2024
@encima encima transferred this issue from supabase/supabase Mar 12, 2024
@encima
Copy link

encima commented Mar 12, 2024

Moving this issue to Postgrest-js repo. Issue is similar to #447 which was fixed recently

@stefan-girlich
Copy link
Author

stefan-girlich commented Apr 10, 2024

A brief update after upgrading supabase-js from 2.39.7 to 2.42.0:

Error in TypeScript type is now as following for the same original code:

const data: SelectQueryError<"Referencing missing column `sum`">[] | null

Using .count() instead of .sum() works as expected, but all other functions (.min(), .max(), .avg()) (src) still produce the error above.

@bnjmnt4n I just had a look into your fix for the similar issue with .count() (diff). Do you think it's sufficient to add sum, min, max, and avg in the same manner? Maybe there's also a way to reference the type AggregateFunctions (src)
Update: I think I found a way; looking into it.

@stefan-girlich
Copy link
Author

stefan-girlich commented Apr 10, 2024

@bnjmnt4n I added test cases which currently fail at compile-time.

@bnjmnt4n
Copy link
Contributor

@stefan-girlich thanks for providing the examples; I'm really busy now so I can probably look at them next week only.

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

3 participants