create function to get the right type when union, intersection etc...