Given that (type_id, group_id) is the PK of widgets it is possible toavoid self-join:
select group_id from widgets where type_id = A or type_id = B group by group_idhaving count(1) = 2;