how can I create the proper typing for a function such that depending on the properties on its input parameters, I get the correct return type when calling this function?