I made a Supabase RPC function and I'm having problems with the typescript definitions generated from:
npx supabase gen types
Below are the generated types, and I want to make current_status nullable, as it can sometimes 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'];
}[];
};
This is my 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 // How do I 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;
$$;