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

.throwOnError() only adjusts types correctly if await is used and is still incorrect if you use `then`

Open MrPiao opened this issue 10 months ago • 1 comments

Bug report

  • [x] I confirm this is a bug with Supabase, not with my own application.
  • [ ] I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

awaiting a query with .throwOnError() correctly eliminates null from the typing. However, if you don't await it and use .then(...) instead, then null is not eliminated from the typing.

To Reproduce

supabase.from('users').select('id').eq('id', id).single().throwOnError().then(({ data }) => { ... });

Expected behavior

Type of data should be { id: string }

Actual behavior

Type of data is { id: string } | null

MrPiao avatar Feb 09 '25 04:02 MrPiao