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

.throwOnError() doesn't do typecheck #563

Open
DavDeDev opened this issue Oct 21, 2024 · 0 comments · May be fixed by #590
Open

.throwOnError() doesn't do typecheck #563

DavDeDev opened this issue Oct 21, 2024 · 0 comments · May be fixed by #590
Labels
bug Something isn't working

Comments

@DavDeDev
Copy link

Bug report

Describe the bug

From my understaning of supabase/supabase-js#92 .throwOnError() should work as if I were typing something like:

	const { data: queryResult, error: queryError } = await supabase
		.from("cohorts")
		.select("id")
		.single();

	if (queryError) {
		throw queryError;
	}
	const thisHasTypeId = queryResult; // This is of type { id: number } NOT NULL!!

In the above case thisHasTypeId is of type {id:number}, but if I try to use .throwOnError():

	const { data: queryResult, error: queryError } = await supabase
		.from("cohorts")
		.select("id")
		.single()
		.throwOnError();


	const thisHasTypeNullToo = queryResult; // This is of type { id: number } | null, WHY NULL??

But here thisHasTypeNullToo has null too! so I would have to do type check as well like this:

	const { data: queryResult, error: queryError } = await supabase
		.from("cohorts")
		.select("id")
		.single()
		.throwOnError();


	const thisHasTypeNullToo = queryResult; // This is of type { id: number } | null, WHY NULL??

	if (queryError) {
		throw queryError;
	}
	const thisDoesNotHaveTypeNull = queryResult; // This is of type { id: number } NOT NULL!!

Expected behavior

It would be nice if the returned data didn't include the null type when using .throwOnError().

@DavDeDev DavDeDev added the bug Something isn't working label Oct 21, 2024
avallete added a commit that referenced this issue Jan 7, 2025
When using throwOnError(), the response type is now more strictly typed:
- Data is guaranteed to be non-null
- Error field is removed from response type
- Response type is controlled by generic ThrowOnError boolean parameter

Fixes #563
@avallete avallete linked a pull request Jan 7, 2025 that will close this issue
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

Successfully merging a pull request may close this issue.

1 participant