.returns() should not allow .single() to be chained
whollacsek opened this issue · comments
Bug report
Describe the bug
.returns() should not allow .single() to be chained otherwise it'll produce incorrect types.
To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
- Go to '…'
- Click on '…'
- Scroll down to '…'
- See error
Expected behavior
A clear and concise description of what you expected to happen.
Screenshots
If applicable, add screenshots to help explain your problem.
System information
- OS: [e.g. macOS, Windows]
- Browser (if applies) [e.g. chrome, safari]
- Version of supabase-js: [e.g. 6.0.2]
- Version of Node.js: [e.g. 10.10.0]
Additional context
Add any other context about the problem here.
You'll want to pass an array type to .returns()
here so the types work properly on .single()
. We also fall back to never
if you pass a non-array type to .returns()
so this shouldn't be an issue:
postgrest-js/src/PostgrestTransformBuilder.ts
Lines 136 to 138 in 9fb56c7
Let me know if you think this is insufficient.
So for clarity's sake, this is what you should do?
const postId = 1;
await supabase.from('posts').select('name, comments(description)').eq('id', postId).limit(1).returns<Post[]>().single();
Because that's not very intuitive. I wrote it as .single().returns<Post>()
because I expected .returns
to be the last in the chain. If this works it's okay, but some documentation on this would be very helpful. And a solution where the order I'd prefer would be even better ;-)