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: safer nullability in functions, domain support #573

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ngasull
Copy link

@ngasull ngasull commented Apr 25, 2023

What kind of change does this PR introduce?

Fixes #842

What is the current behavior?

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::text, arg
$$;

Generated type with supabase gen types typescript --local

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

What is the new behavior?

Generated types should be:

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

Please review tests for more details on new expected behavior.

  • Stop accepting non-nullable types in generated function arguments and return types.
  • Add support for domains and take their nullability into account.
  • Centralize nullability and array logic in pgTypeToTsType.

Additional context

This is obviously a breaking change for most users using functions. It is however the safe way, exposing sound types.

Add support for domains and take their nullability into account.
Centralize logic in `pgTypeToTsType`.
@ngasull ngasull requested review from a team as code owners April 25, 2023 09:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Typescript gen : invalid SQL Function types
1 participant