I want to parse data from an axios request on typescript
I got two interfaces
interface Department{
code: string;
name: string;
country: string;
}
interface User {
name: string;
email: string;
departments: Department[];
}
I got an endpoint which returns data like this
[
{
"name": "Estonia",
"email": "email",
"phone": 12345,
"weight": "60kg",
"country": "US",
"departments": [
{
"code": 1,
"name": "depto 1",
"country": "US"
},
{
"code": 2,
"name": "depto 2",
"country": "FR"
}
]
[...]
}
]
The endpoint retrieves a lot of data which I don't need, I just want to retrieve attributes I've defined on the interface, is this possible?
I have tried this, but I got all attributes
axios.get<User[]>('http://localhost/users').then(({ data }) => {
console.log(typeof data, data);
});