I have a snippet of code
const fetcher2 : Fetcher<Data,string> = async(...args) => await fetch(...args).then(r=>r.json())
const {data:{name}} = useSWR("http://localhost:3000/my_api/name", fetcher2)
and with it Data's type:
type Data = {
name: string,
vegetable: {
potato: string
}
}
You can definitely see that name is there and I can destructure it, but it gives me an error under data saying:
Property 'name' does not exist on type 'Data | undefined'.ts(2339)
Are you not allowed to destructure the data variable received from SWR?