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

Typescript gen : invalid SQL Function types #842

Open
2 tasks done
ngasull opened this issue Apr 21, 2023 · 3 comments · May be fixed by #573
Open
2 tasks done

Typescript gen : invalid SQL Function types #842

ngasull opened this issue Apr 21, 2023 · 3 comments · May be fixed by #573
Labels
bug Something isn't working

Comments

@ngasull
Copy link

ngasull commented Apr 21, 2023

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

For both input and input types, typescript generation of SQL functions is invalid in some cases :

  • Primitive types are generated as non-nullable (type instead of type | null) even though the function may accept NULL as input or output
  • Domain types are generated as unknown

I think that this bug is not caused by a PostgreSQL limitation as views produce the correct typing : primitives are nullable, domains generate as their underlying type and when domains are marked NOT NULL they are even non-nullable in typescript.

To Reproduce

CREATE DOMAIN strict_text AS text NOT NULL;

CREATE FUNCTION some_function(arg strict_text)
RETURNS table (nulltext text, stricttext strict_text)
LANGUAGE SQL AS $$
   SELECT NULL::uuid, arg
$$;

Generated type with supabase gen types typescript --local

export interface Database {
  public: {
    Functions: {
      some_function: {
        Args: {
          arg: unknown
        }
        Returns: {
          nulltext: string
          stricttext: unknown
        }[]
      }
    }
  }
}

Expected behavior

Generated types should be

export interface Database {
  public: {
    Functions: {
      some_function: {
        Args: {
          arg: string
        }
        Returns: {
          nulltext: string | null
          stricttext: string
        }[]
      }
    }
  }
}

System information

  • OS: [e.g. Linux NixOS]
  • Version of supabase CLI: 1.50.8
  • Version of Node.js: 18.15.0

Additional context

I ❤️ the work being done and the mindset at Supabase. I believe strict typing is crucial to the success of a "backend in the DB" and I could help with a PR if I'm being given some pointers to the code responsible of the TS generation 👋

@ngasull ngasull added the bug Something isn't working label Apr 21, 2023
@sweatybridge
Copy link
Contributor

Thanks for the detailed bug report. The typescript generation code is in postgres-meta repo if you are keen to take a look.

@ngasull
Copy link
Author

ngasull commented Apr 25, 2023

Just pushed a PR for this issue, feel free to have a look! 🙂

@mwoss
Copy link

mwoss commented Nov 13, 2023

That would be a great addition to the client library tho :3 I would love to see it live in the near future!

@sweatybridge sweatybridge transferred this issue from supabase/cli Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants