I have developed a function that triggers an axios
Request. I am working with typescript
and I am avoiding the use of any
for defining return data types of both the function and the axios
request itself.
The issue arises when the returned object contains the parameter id, which in turn is an object. To be honest, I have never encountered such a structure before. I am unsure about its nature and whether it involves some fundamental concepts that I might not be familiar with. It has been challenging to find relevant information through online searches.
I aim to create a custom typescript interface
based on this object. However, I am struggling to figure out where to begin.
Any assistance will be highly appreciated.
This snippet represents a portion of the resulting object:
{
data{
'12345': { // params.id --> causing my poblem
address: {
...,
}}}
}
Here is my function:
async function fetchData (): Promise<IReturnData[]> {
const {data} = await axios.get<IReturnData>(`....${id}`) // in our case 12345
return Object.entries(data.data)[0];
}
How should I define the interface IReturnData ?
export interface IReturnData {
data {
string: { adress: Adress......
}}}
or
export interface IReturnData {
data {
"1234 but that will change on every request": {
adress: Adress......
}}}