logo

该视频仅会员有权观看

立即开通课程「Next.js 前端应用开发实践」权限。

¥
199
/ 年

设置 Next.js 框架里的 fetch 请求回来的数据类型

  • 创建了一个名为 tap.ts 的新文件,在 app post 目录下。
  • tap.ts 文件中定义了多个类型,包括 post filepost user,和 post
    • post file 类型包含一个 id(类型为 number)属性。
    • post user 类型包含 id(类型为 number)与 name(类型为 string)属性。
    • post 类型包括 id(类型为 number)、titlecontent(类型均为 string),以及 file(类型是 post file)和 user(类型是 post user)属性。
  • 导出了一个 post list 类型,它是一个包含 post 类型项目的数组。
  • post serviceget post 方法中,使用断言指定返回类型为 promise post list
  • post page,鼠标悬停在 post 数据上会显示其类型是 post list