I am faced with a situation where I have two functions that essentially perform the same task, but differ in the types of their inputs and outputs. I am exploring ways to combine these functions into one, and one potential solution is to use a union type. However, my requirement is that when the input is a member of the union type, the returned value must also be the same type.
const getViewStyle = (styles: ViewStyle[]): ViewStyle => {
return Object.assign({}, ...styles);
};
const getTextStyle = (styles: TextStyle[]): TextStyle => {
return Object.assign({}, ...styles);
};