postgrest-js icon indicating copy to clipboard operation
postgrest-js copied to clipboard

.throwOnError() doesn't do typecheck

Open DavDeDev opened this issue 1 year ago • 0 comments

Bug report

Describe the bug

From my understaning of https://github.com/supabase/supabase-js/issues/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 avatar Oct 21 '24 00:10 DavDeDev