From 95baeff642684d6a61c58c4ed8bcd96f75c8975d Mon Sep 17 00:00:00 2001 From: Joseph Chan Date: Wed, 25 Jun 2025 16:35:33 -0400 Subject: [PATCH] Update part9c.md: update zod to v4 updated zod syntax for the latest version of zod (v4). * updated `z.nativeEnum() --> z.enum()` ([link to docs](https://zod.dev/api?id=enums)) * updated `z.string().date() --> z.iso.date()` ([link to docs](https://zod.dev/api?id=iso-dates) --- src/content/9/en/part9c.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/content/9/en/part9c.md b/src/content/9/en/part9c.md index 38bd9628c2..b30287b058 100644 --- a/src/content/9/en/part9c.md +++ b/src/content/9/en/part9c.md @@ -1555,7 +1555,7 @@ export const toNewDiaryEntry = (object: unknown): NewDiaryEntry => { const newEntry: NewDiaryEntry = { weather: parseWeather(object.weather), visibility: parseVisibility(object.visibility), - date: z.string().date().parse(object.date), // highlight-line + date: z.iso.date().parse(object.date), // highlight-line comment: z.string().optional().parse(object.comment) // highlight-line }; @@ -1578,9 +1578,9 @@ export const toNewDiaryEntry = (object: unknown): NewDiaryEntry => { if ('comment' in object && 'date' in object && 'weather' in object && 'visibility' in object) { const newEntry: NewDiaryEntry = { - weather: z.nativeEnum(Weather).parse(object.weather), // highlight-line - visibility: z.nativeEnum(Visibility).parse(object.visibility), // highlight-line - date: z.string().date().parse(object.date), + weather: z.enum(Weather).parse(object.weather), // highlight-line + visibility: z.enum(Visibility).parse(object.visibility), // highlight-line + date: z.iso.date().parse(object.date), comment: z.string().optional().parse(object.comment) }; @@ -1596,9 +1596,9 @@ We have so far just used Zod to parse the type or schema of individual fields, b ```js const newEntrySchema = z.object({ - weather: z.nativeEnum(Weather), - visibility: z.nativeEnum(Visibility), - date: z.string().date(), + weather: z.enum(Weather), + visibility: z.enum(Visibility), + date: z.iso.date(), comment: z.string().optional() }); ```