Skip to content

Return types for RPC cannot have nullable properties #841

Open
@dbuhon

Description

@dbuhon

The supabase gen types appears to lack support for RPC functions returning objects with nullable properties.

Steps to reproduce:

Define an RPC function:

   CREATE TYPE status_type_enum AS ENUM ('rotten', 'ripe'); 
   
   CREATE FUNCTION get_bananas(
     _limit INT DEFAULT NULL,
     _offset INT DEFAULT 0
   )
   RETURNS TABLE (
     id UUID,
     text TEXT,
     current_status status_type_enum -- Is there a way to make this nullable in TS?
   )
   LANGUAGE plpgsql
   AS $$
   BEGIN
     RETURN QUERY
     SELECT
       b.id,
       b.text,
       s.status_type AS current_status
     FROM bananas b
     LEFT JOIN statuses s ON b.id = s.banana_id AND s.user_id = auth.uid()
     LIMIT _limit
     OFFSET _offset;
   END;
   $$;

Run the command:

npx supabase gen types

Examine the generated types:
It doesn't seem possible to make current_status nullable out of the box, even though it can be missing.

   get_bananas: {
     Args: {
       _limit?: number;
       _offset?: number;
     };
     Returns: {
       id: string;
       text: string;
       current_status: Database['public']['Enums']['status_type_enum'];
       // current_status: null | Database['public']['Enums']['status_type_enum'];
     }[];
   };

Workaround

Extend the generated types from another file to overwrite properties.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions