Typescript return type for Functions

I really appreciate the supabase gen types typescript utility in the CLI tool. One thing I can't get to work is when I define Postgres Functions, it won't determine the return type based on the the function. For example, given this function
create or replace function shifts_by_week(date timestamp default null)
returns setof shifts
as $$
select * from shifts where date_trunc('week', coalesce($1, current_date) + interval '1 day') - interval '1 day' = date_trunc('week', shifts.date + interval '1 day') - interval '1 day';
$$ language sql;
create or replace function shifts_by_week(date timestamp default null)
returns setof shifts
as $$
select * from shifts where date_trunc('week', coalesce($1, current_date) + interval '1 day') - interval '1 day' = date_trunc('week', shifts.date + interval '1 day') - interval '1 day';
$$ language sql;
Where I'm specifying the return is setof shifts which is a table in my schema. The generated type for this is
Functions: {
shifts_by_week: {
Args: { date: string }
Returns: unknown
}
}
Functions: {
shifts_by_week: {
Args: { date: string }
Returns: unknown
}
}
I can manually update the file, sure, but it is auto-generated, so I'd rather not. And yes, I could also build a bash script that will generate the types and then mutate them at the end, but I'd rather not.
1 Reply
meenie
meenieOP3y ago
I can also see that it's not using the correct types as well. I'm assuming the Functions ability with this feature is limited.

Did you find this page helpful?