You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Our database includes what are referred to in the PostgREST documentation as computed fields. These are Postgres functions on table types
When reviewing the output of running npx supabase gen types typescript, we are seeing that alongside the actual columns of a table, the computed fields are listed
To Reproduce
Steps to reproduce the behavior:
Ensure that you have a table in your database with a function on that table, e.g. run the following statements from the PostgREST documentation against your local Supabase database
CREATETABLEpeople (
first_name text
, last_name text
, job text
);
-- a computed field that combines data from two columnsCREATEFUNCTIONfull_name(people)
RETURNS textAS $$
SELECT $1.first_name ||''|| $1.last_name;
$$ LANGUAGE SQL;
Generate TypeScript types by running npx supabase gen types typescript --local
Observe that the Row for the people table indicates that there is a full_name property, for example
Expected behavior
I'm curious if others think that this behavior is desirable. For us, this has been a problem because the generated types lead TypeScript to indicate that the computed fields exist on a row selected from the database. This led us to write some code that passed ts-lint, but caused an unexpected bug at runtime
For example, if one were to initialize the Supabase client with these generated types and then run
the returned data would not include full_name, but TypeScript would think that data.full_name is either string | null. Instead, to have full_name one needs to explicitly include it by running
Describe the bug
Our database includes what are referred to in the PostgREST documentation as computed fields. These are Postgres functions on table types
When reviewing the output of running
npx supabase gen types typescript
, we are seeing that alongside the actual columns of a table, the computed fields are listedTo Reproduce
Steps to reproduce the behavior:
npx supabase gen types typescript --local
Row
for thepeople
table indicates that there is afull_name
property, for exampleExpected behavior
I'm curious if others think that this behavior is desirable. For us, this has been a problem because the generated types lead TypeScript to indicate that the computed fields exist on a row selected from the database. This led us to write some code that passed ts-lint, but caused an unexpected bug at runtime
For example, if one were to initialize the Supabase client with these generated types and then run
the returned data would not include
full_name
, but TypeScript would think thatdata.full_name
is eitherstring | null
. Instead, to havefull_name
one needs to explicitly include it by runningSystem information
Rerun the failing command with
--create-ticket
flag.The text was updated successfully, but these errors were encountered: