I'm grappling with a function that yields an Output generic type. In this function, I initiate an API request that responds with a json object. My aim is to have the function return this json object in the Output Generic type format
Take a look at this example:
function myCustomFunc<Output>(): Promise<Output> {
const apiResponse: {[Key: string]: string} = fetchFromAPI()
return apiResponse as Output
}
My attempts to implement this are met with TypeScript error messages indicating the mismatch in type definitions, which comes as no surprise. I believe the ideal solution would involve creating a function to map each property from apiResponse to those of the Output type, but I'm unsure how to extract the attribute and value types of a Generic Type