Skip to content

Null should be included in return type when using json path (->) #1635

@joeldomke

Description

@joeldomke
  • 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 json path in select() the type inference produces non nullable types even when the return type might be null.

To Reproduce

  1. Create a table with a column json_col that can be null and override the database type to be { a: string } | null
  2. Create a query with .select('json_col->a')
  3. Return type will be { a: string }

Expected behavior

This query will actually return `{ a: null } when the column is null. This should be reflected in the type.

This should be the case when the column is nullable or when one of the properties along the path is nullable.

I currently only have this type safety when I do

const { data } = ...select('json_col');

data!.json_col.a; // Object is possibly 'null'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghas workaroundIssue has a valid workaround.postgrest-jsRelated to the postgrest-js library.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions