Skip to content

Typescript gen : invalid SQL Function types #842

Open
@ngasull

Description

@ngasull

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 👋

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions