Is it possible to write a function with types (similar to the one at bottom) so that it can be used in the following ways. Either;
parseApiResponse(apiResponse); // returns TParsedResponse
// or
parseApiResponse<TSpecificParsedResponse>(apiResponse); // returns TSpecificParsedResponse
where
type TApiResponse = {/* some complex non-specific raw data */}
type TParsedResponse = {[key:string]: string | number}[] // array of objects with any string as a key
type TSpecificParsedResponse = {name:string, age:number}[]
Here's my shoddy first attempt
const parseApiResponse = <T extends {}>(apiResponse: TApiResponse): T => {
//some code here
return parsedResponse;
};