Skip to content

Inferred types for nullable columns after not null checks should be non-nullable #1360

Open
@chesterhow

Description

@chesterhow

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

For nullable columns, even if the query includes a not null check (e.g. .not("column_name", "is", null)), the inferred return type for that column is still nullable.

To Reproduce

  1. Create a blog_posts table with a nullable column, published_at.
create table blog_posts(
  id           uuid        primary key default uuid_generate_v4(),
  title        text        not null,
  created_at   timestamptz not null default now(),
  published_at timestamptz
);
  1. Query this table to retrieve all published blog posts.
const { data } = await supabase
  .from("blog_posts")
  .select("*")
  .not("published_at", "is", null);
  1. Observe that the published_at field in data is still typed as nullable.
const data: {
  id: string;
  title: string;
  created_at: string;
  published_at: string | null; // <-- why is this nullable?
}[] | null

Expected behavior

Inferred type for published_at should not be nullable.

System information

  • Version of supabase-js: 2.48.0

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