Skip to content

Computed fields not present in supabase gen types #5067

@jleclanche

Description

@jleclanche

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

supabase gen types typescript does not include computed fields as selectable fields on the table type. This means that selecting a computed field in the Supabase JS client produces a type error, even though PostgREST serves it correctly at runtime.

The type generator already has all the information needed to detect computed fields: any entry in Functions whose Args is a single parameter of type Tables.<X>.Row is a computed field on table <X>, per the PostgREST convention.

To Reproduce

  1. Create a table and a computed field function:
create table public.posts (
  id uuid primary key default gen_random_uuid(),
  title text not null,
  body text not null
);

create or replace function public.title_length(post public.posts)
returns int
language sql stable
as $$
  select length(post.title);
$$;
  1. Run supabase gen types typescript. The generated types include:
// Under Functions -- the function is recognized
title_length: {
  Args: { post: Database["public"]["Tables"]["posts"]["Row"] };
  Returns: number;
};

// Under Tables.posts.Row -- no title_length
Row: {
  id: string;
  title: string;
  body: string;
};
  1. Use the Supabase JS client:
const { data } = await supabase
  .from("posts")
  .select("*, title_length");
// TypeScript error: column 'title_length' does not exist on 'posts'
// But PostgREST returns the data correctly at runtime

Expected behavior

The type generator should expose computed fields as selectable (but not insertable/updatable) on the parent table. For example, by adding a ComputedFields key:

posts: {
  Row: {
    id: string;
    title: string;
    body: string;
  };
  ComputedFields: {
    title_length: number;
  };
  Insert: { ... };
  Update: { ... };
  Relationships: [ ... ];
};

The .select() type inference would then union Row with ComputedFields when resolving selectable columns. The detection is mechanical: any function in Functions whose Args has a single parameter typed as Tables.<X>.Row is a computed field on table <X>.

System information

  • OS: Linux
  • Version of supabase-js: 2.49.4
  • Version of Supabase CLI: 2.20.5
  • Version of Node.js: 22

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions