Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the inconsistency of NewEntrySchema in code snippets #3857

Open
wants to merge 1 commit into
base: source
Choose a base branch
from
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
12 changes: 6 additions & 6 deletions src/content/9/en/part9c.md
Original file line number Diff line number Diff line change
Expand Up @@ -1595,7 +1595,7 @@ We have so far just used Zod to parse the type or schema of individual fields, b


```js
const newEntrySchema = z.object({
const NewEntrySchema = z.object({
weather: z.nativeEnum(Weather),
visibility: z.nativeEnum(Visibility),
date: z.string().date(),
Expand All @@ -1607,7 +1607,7 @@ Now it is just enough to call _parse_ of the defined schema:

```js
export const toNewDiaryEntry = (object: unknown): NewDiaryEntry => {
return newEntrySchema.parse(object);
return NewEntrySchema.parse(object);
};
```

Expand Down Expand Up @@ -1654,7 +1654,7 @@ So besides the type _NewDiaryEntry_ we have also the Zod schema _NewEntrySchema_

```js
import { z } from 'zod';
import { newEntrySchema } from './utils'
import { NewEntrySchema } from './utils'

export interface DiaryEntry {
id: number;
Expand All @@ -1665,13 +1665,13 @@ export interface DiaryEntry {
}

// infer the type from schema
export type NewDiaryEntry = z.infer<typeof newEntrySchema>;
export type NewDiaryEntry = z.infer<typeof NewEntrySchema>;
```

We could take this even a bit further and define the _DiaryEntry_ based on _NewDiaryEntry_:

```js
export type NewDiaryEntry = z.infer<typeof newEntrySchema>;
export type NewDiaryEntry = z.infer<typeof NewEntrySchema>;

export interface DiaryEntry extends NewDiaryEntry {
id: number;
Expand All @@ -1690,7 +1690,7 @@ We can now get rid of this method altogether

```js
export const toNewDiaryEntry = (object: unknown): NewDiaryEntry => {
return newEntrySchema.parse(object);
return NewEntrySchema.parse(object);
};
```

Expand Down