Open
Description
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
Labels
No labels