Infer return type using generics