How to make Generic Functions that change return value type according to the parameter values type in TypeScript?