Working with Typescript while making an API call with axios and have come across a nested data scenario.
Although I believe to have it typed correctly, I keep receiving a Typescript error stating Unsafe return on an any typed value and Unsafe member access .data on an any value for the return response.data.data[0]; line of my try/catch. Can someone provide some clarity around why my types aren't working as I "think" they are?
export interface Source {
curr: string;
uuid: string;
rate: string;
}
export interface Response {
data: {
data: Array<Source>;
};
}
async function getSource({ curr, uuid, rate }: Source): Promise<AxiosResponse<Response>> {
const requestConfig: AxiosRequestConfig = {
method: 'get',
url: '/url',
};
try {
const response = await axios(requestConfig);
return response.data.data[0];
} catch (err) {
throw new Error('error');
}
}
axios(requestConfig)returnsAxiosPromise<any>, soresponse.datais of typeany.