Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/content/9/en/part9c.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand All @@ -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)
};

Expand All @@ -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()
});
```
Expand Down