Bug report
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
- 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);
$$;
- 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;
};
- 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
Bug report
Describe the bug
supabase gen types typescriptdoes 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
FunctionswhoseArgsis a single parameter of typeTables.<X>.Rowis a computed field on table<X>, per the PostgREST convention.To Reproduce
supabase gen types typescript. The generated types include:Expected behavior
The type generator should expose computed fields as selectable (but not insertable/updatable) on the parent table. For example, by adding a
ComputedFieldskey:The
.select()type inference would then unionRowwithComputedFieldswhen resolving selectable columns. The detection is mechanical: any function inFunctionswhoseArgshas a single parameter typed asTables.<X>.Rowis a computed field on table<X>.System information