I am fetching data from an API in Nuxt3. I am using typescript and I wish to define the type of data that I will get. How do I specify this?
<script lang="ts" setup>
interface APIBody {
/* properties defined here */
}
const {data} = await useFetch("api_url here")
</script>
<template>
{{ data.name.officialName }}
<template>
I get an error in the template
where I am displaying data.name.officialName
However, while running the code in the browser, the website works fine.
I tried the following code but I am receiving a different error now.
<script lang="ts" setup>
interface APIBody {
/* properties defined here */
}
const typedData = ref<APIBody[]>()
const {data} = await useFetch("api_url here")
typedData.value = data as APIBody[] // -> error here
</script>
<template>
{{ data.name.officialName }}
<template>
The error in this case is:
