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

Specify that data object can be null #9817

Closed
hyunbinseo opened this issue Oct 24, 2022 · 2 comments
Closed

Specify that data object can be null #9817

hyunbinseo opened this issue Oct 24, 2022 · 2 comments
Assignees
Labels
documentation Improvements or additions to documentation

Comments

@hyunbinseo
Copy link

Improve documentation

Link

Typescript Support

supabase-js always returns a data object (for success), and an error response (for unsuccessful requests).

Describe the problem

Prefer: return=minimal is set by default now.

Therefore, if .select() is not chained, successful requests return null for both data and error.

Describe the improvement

Current documentation is technically correct - successful requests do return data object of null or an array.

However, being more explicit would not hurt.

supabase-js always returns a data array (for successful requests with .select() chained) …

Additional context

The following code will always throw an error for both successful and unsuccessful requests.

const { data, error } = await supabase
  .from('countries')
  .insert({ id: 1, name: 'Denmark' });

if (!data || error) throw new Error();

Successful responses used to return an data array, so the above code was valid in v1.

@hyunbinseo hyunbinseo added the documentation Improvements or additions to documentation label Oct 24, 2022
@soedirgo soedirgo transferred this issue from supabase/supabase-js Oct 25, 2022
@soedirgo soedirgo self-assigned this Oct 25, 2022
@GaryAustin1
Copy link
Contributor

I believe in the case of .maybeSingle a .select() will also return null for 0 rows matched.

@charislam
Copy link
Contributor

Closing as the Typescript support documentation has changed significantly and typing support should be better now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

4 participants