DEV Community

Discussion on: Do you prefer Fetch or Axios?

Collapse
 
adamazad profile image
Adam Azad

What about?

interface Fruit {
  id: string;
  name: string;
}

const { data } = await axios.get<Fruit[]>('/fruits');
Enter fullscreen mode Exit fullscreen mode

Now data is an array of objects Fruit

Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt

Actually, it's just a fake typing.

It depends on the "real" data, whether it gets JSON.parse() or not.