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
Open

.throwOnError() doesn't do typecheck #563

DavDeDev opened this issue Oct 21, 2024 · 0 comments
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
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

1 participant