Skip to content

Null should be included in return type when using maybeSingle #647

@Refrase

Description

@Refrase
  • 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

When I use a .limit(1).maybeSingle() in select() the type inference produces non nullable types even when the return type might be null.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Create a tableX with columnX of type number
  2. Query the table like with following query
await supabase
    .from('tableX')
    .select('*')
    .match({
      columnX: 999, <-- Number for which a row is not found
    })
    .limit(1)
    .maybeSingle()
  1. Typescript will not include null in a return type union even when a fresh Supabase Database type has been exported and is being passed to createServerClient.

Expected behavior

For null to be included in a union return type.

Screenshots

If applicable, add screenshots to help explain your problem.

System information

  • OS: macOS
  • Version of supabase-js: 2.57.4
  • Version of postgrest-js: 1.21.4
  • Version of Typescript: 4.9.5

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