Skip to content

throwOnError with await returns nullable type #801

Closed
@dogukanakkaya

Description

@dogukanakkaya

Bug report

  • 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

.throwOnError should return non-nullable type because since in a case of error it will throw instead of returning an error object with null data object.

To Reproduce

See below code for example:

const { data, error } = await supabase.from('groups').insert({ name }).select('id').throwOnError().single()

In this example return type is nullabe { data: { id: string } } | null but it shouldn't because it'll throw on error.

In this case I have to do below to correct typing which doesn't make any sense to do extra if checks even though it's unnecessary:

const { data, error } = await supabase.from('groups').insert({ name }).select('id').throwOnError().single()

if (error) throw error

Expected behavior

If .throwOnError called return type must be { data: NonNullable<...>, error: null } or even without error object if possible.

Screenshots

Screenshot 2023-06-29 at 12 47 37

System information

  • OS: MacOS
  • Version of supabase-js: 2.26.0
  • Version of Node.js: 20.3.1
  • Version of Typescript: 5.1.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions