unify generic return with with_type if available (closes #1868)