From ba044d20563b58a64f72f0c035caf31194b8a825 Mon Sep 17 00:00:00 2001 From: Tom Raine <157725735+WingRa7@users.noreply.github.com> Date: Sun, 7 Sep 2025 19:07:02 +0800 Subject: [PATCH] Update part9c.md: zod deprecated syntax new zod syntax for date and enum --- 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 38bd9628c21..b30287b0582 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() }); ```