Skip to content

TypeScript - returned typed from query should reflect query filterย #1427

@Magnuti

Description

@Magnuti

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

Using query filters like .not("<column>", "is", null); does not produce types that correctly represents the returned data.

To Reproduce

Create a table posts

create table "public"."posts" (
    "id" bigint generated by default as identity not null,
    "content" text not null,
    "published_at" date
);

Generate types from the database schema.

supabase gen types typescript --local --schema public > functions/_shared/supabase.gen.ts

Write some TypeScript code to fetch posts.

import { createClient } from "@supabase/supabase-js";
import { Database } from "../_shared/supabase.gen";

const getPublishedPosts = async () => {
  const supabase = createClient<Database>("supabaseUrl", "supabaseAnonKey");

  const result = await supabase
    .from("posts")
    .select("*")
    .not("published", "is", null);

  if (result.error) {
    throw result.error;
  }

  const data = result.data;
};

Expected behavior

data should be of type

const data: {
    content: string;
    id: number;
    published_at: string; // ๐Ÿ‘ˆ string, not string | null
}[]

since we filtered published_at on NOT NULL in the query.

Actual behavior

data is of type

const data: {
    content: string;
    id: number;
    published_at: string | null;
}[]

System information

supabase --version: 2.23.4
node --version: v22.15.0

  "devDependencies": {
    "typescript": "5.8.3",
    "@supabase/supabase-js": "2.49.8"
  },

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions