属性“名称”类型“RepositoryResponse[]”上不存在。打字稿

发布于 2025-01-14 19:11:36 字数 682 浏览 2 评论 0原文

我正在尝试从 GitHub API 获取数据,但出现错误:界面中不存在 API 中的值。 API URL:https://api.github.com/repos/facebook/react

      interface Repository {
      name: string;
      avatar_url: string;
      html_url: string;
      owner : {
        login: string;
      }
    }
    
    interface RepositoryResponse {
      data: Repository
    }


  const [repositoryData,setRepositoryData] = useState<RepositoryResponse[]>([]);


//Component

<p> {repositoryData.name}  </p>
<p>   {repositoryData.owner.login}  </p>
<p> {repositoryData.html_url}  </p>

I am trying to fetch data from the GitHub API, but give me the error that values from the API does not exist in the interface.
API URL : https://api.github.com/repos/facebook/react

      interface Repository {
      name: string;
      avatar_url: string;
      html_url: string;
      owner : {
        login: string;
      }
    }
    
    interface RepositoryResponse {
      data: Repository
    }


  const [repositoryData,setRepositoryData] = useState<RepositoryResponse[]>([]);


//Component

<p> {repositoryData.name}  </p>
<p>   {repositoryData.owner.login}  </p>
<p> {repositoryData.html_url}  </p>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酷到爆炸 2025-01-21 19:11:36

repositoryData 是一个 RepositoryResponse 数组,其中包含一个存储库的字段数据。


repositoryData.map({data} => {return (
<p> {data.name}  </p>
<p>{data.owner.login}</p>
<p> {data.html_url}</p>)
})

repositoryData is an array of RepositoryResponse which contains one filed data which is a Repository.


repositoryData.map({data} => {return (
<p> {data.name}  </p>
<p>{data.owner.login}</p>
<p> {data.html_url}</p>)
})

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文