Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect typescript types generated for functions returning records or table row types (generated as unknown) #2227

Open
Donnerstagnacht opened this issue May 1, 2024 · 0 comments
Labels

Comments

@Donnerstagnacht
Copy link

Describe the bug
If a postgres function returns a record or a table row type, the generated return type is "unknonwn" which is incorrect.

To Reproduce

  1. Create a function which returns a record or a table row type.
  2. Generate types (supabase gen types typescript --project-id "<project_id>" --schema <schema_id> > supabase/types/supabase.ts")

Expected behavior
It should return the table row type or record type or as a workarround a value which is not "unknown". The return type "unknown" removes type safety but also complicates working with the returned data.

Code snippets
If I have a table

CREATE TABLE (
    id  uuid,
    name text
)

and I create a function returning a record of that table

CREATE FUNCTION read_group_record(group_id uuid)
    RETURNS record
DECLARE
    group_record record;
BEGIN
    SELECT *
    INTO group_record
    FROM
        groups
    WHERE
        groups.id = group_id;
    RETURN group_record;
END

or a table row type of that table

CREATE FUNCTION read_group_table_row_type(group_id uuid)
    RETURNS groups
DECLARE
    group_record groups;
BEGIN
    SELECT *
    INTO group_record
    FROM
        groups
    WHERE
        groups.id = group_id;
    RETURN group_record;
END

the generated types are:

      read_group_record: {
        Returns: Record<string, unknown>
      }
      read_group_table_row_type: {
        Returns: unknown
      }

But I would have expected something like

      read_group_table_row_type: {
        Returns: {
           id: string
           name: string
        }
      }

System information

  • Version of OS: Windows 11
  • Version of CLI: v1.163.6
  • Version of Docker: Docker Desktop 4.24.2 (124339)
  • Versions of services: [Generated types | Output command generate types]

Additional context

  • Browser [e.g. edge, chrome]

PS: This is my first bug report. If you require more information, I am happy to provide them. If I should define the return types differently to use the type generation, please provide me an example and I will close the issue.

@Donnerstagnacht Donnerstagnacht changed the title Types generated for functions returning records or table row types are unknown (incorrect) Incorrec typescript types generated for functions returning records or table row types (generated as unknown) May 1, 2024
@Donnerstagnacht Donnerstagnacht changed the title Incorrec typescript types generated for functions returning records or table row types (generated as unknown) Incorrect typescript types generated for functions returning records or table row types (generated as unknown) May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants