In my app, I have a function that handles all API requests. Any interaction I make goes through this function.
I'm trying to set a specific return type for this function, but the return type is of a class. In order to use the methods of this class, I need to instantiate it dynamically.
const sendRequest = async <T>(uri: string, options: any): Promise<T> => {
// ... request logic here.
const data = await response.json();
return new T(data);
}
As expected, this approach didn't work. I'm wondering if there's a workaround or solution that would allow me to return a class instance when passing in the data?