小编nur*_*fah的帖子

如何为深层嵌套对象编写 zod 模式

我有以下数据:

{
  "2022-06-01": {
    "09:00am": {
      "time_table_id": 1,
      "job_id": 4,
      "start_working_time": "09:00am",
      "end_working_time": "09:00pm",
      "work_duration": "12:00:00",
      "merchant_name": "Brands Outlet @ The Starling",
      "address2": "Jalan SS 21/37, Damansara Utama",
      "job_name": "Pro hero",
      "job_application_status": "Hired"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

这是我的模式,但它给了我一个 zod 错误。

const apiScheme = z.object({
  Date: z.object({
    Time: z.object({
      date: z.string(),
      time_table_id: z.number().nullable(),
      job_id: z.number(),
      start_working_time: z.string(),
      end_working_time: z.string(),
      // work_duration: z.string(),
      // merchant_name: z.string(),
      // address2: z.string(),
      job_name: z.string(),
      job_application_status: z.string(),
    }),
  }),
});

// -- snip -- (React code):

const …
Run Code Online (Sandbox Code Playgroud)

api android typescript react-native zod

4
推荐指数
1
解决办法
2万
查看次数

标签 统计

android ×1

api ×1

react-native ×1

typescript ×1

zod ×1