I add here the complete solution for creating types in a simple script, without the need of creating a function just for this purpose.
--create types
DO $$
BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname="my_type") THEN
CREATE TYPE my_type AS
(
--my fields here...
);
END IF;
--more types here...
END$$;