10000 docs: fix some typos on the "Defining schemas" page (#4595) · colinhacks/zod@5cc04f3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5cc04f3

Browse files
authored
docs: fix some typos on the "Defining schemas" page (#4595)
* Update api.mdx * fix typo * fix typo * fix typo * remove extra space * add missing code block syntax highlighting * fix misuse of z.intersection * customized error message should be passed * missing space * use correct variable name
1 parent 74458e9 commit 5cc04f3

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

packages/docs/content/api.mdx

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ schema.parse(null); // => "null"
5252

5353
| Zod API | Coercion |
5454
|--------------------------|----------------------------|
55-
| `z.coerce.string()` | `new String(value)` |
56-
| `z.coerce.number()` | `new Number(value)` |
57-
| `z.coerce.boolean()` | `new Boolean(value)` |
55+
| `z.coerce.string()` | `String(value)` |
56+
| `z.coerce.number()` | `Number(value)` |
57+
| `z.coerce.boolean()` | `Boolean(value)` |
5858
| `z.coerce.bigint()` | `BigInt(value)` |
5959
| `z.coerce.date()` | `new Date(value)` |
6060

@@ -308,7 +308,7 @@ schema.parse("mailto:noreply@zod.dev"); // ✅
308308
schema.parse("sup"); //
309309
```
310310

311-
As you can see this is quite permissive. Internally this uses the `new URL()` constructor to valid inputs; this behavior may differ across platforms and runtimes but it's the mostly rigorous way to validate URIs/URLs on any given JS runtime/engine.
311+
As you can see this is quite permissive. Internally this uses the `new URL()` constructor to validate inputs; this behavior may differ across platforms and runtimes but it's the mostly rigorous way to validate URIs/URLs on any given JS runtime/engine.
312312

313313
To validate the hostname against a specific regex:
314314

@@ -718,7 +718,7 @@ strbool.parse("1") // => true
718718
strbool.parse("yes") // => true
719719
strbool.parse("on") // => true
720720
strbool.parse("y") // => true
721-
strbool.parse("enable") // => true
721+
strbool.parse("enabled") // => true
722722

723723
strbool.parse("false"); // => false
724724
strbool.parse("0"); // => false
@@ -861,7 +861,7 @@ const hello = z.templateLiteral(["hello, ", z.string()]);
861861
// `hello, ${string}`
862862

863863
const cssUnits = z.enum(["px", "em", "rem", "%"]);
864-
const css = z.templateLiteral([z.number(), cssUnits ]);
864+
const css = z.templateLiteral([z.number(), cssUnits]);
865865
// `${number}px` | `${number}em` | `${number}rem` | `${number}%`
866866

867867
const email = z.templateLiteral([
@@ -950,7 +950,7 @@ Dog.parse({ name: "Yeller", extraKey: true });
950950

951951
To define a *catchall schema* that will be used to validate any unrecognized keys:
952952

953-
```
953+
```ts z.object
954954
const DogWithStrings = z.object({
955955
name: z.string(),
956956
age: z.number().optional(),
@@ -1507,10 +1507,10 @@ type c = z.infer<typeof c>; // => number
15071507
This can be useful for intersecting two object types.
15081508

15091509
```ts
1510-
const Person = z.intersection({ name: z.string() });
1510+
const Person = z.object({ name: z.string() });
15111511
type Person = z.infer<typeof Person>;
15121512

1513-
const Employee = z.intersection({ role: z.string() });
1513+
const Employee = z.object({ role: z.string() });
15141514
type Employee = z.infer<typeof Employee>;
15151515

15161516
const EmployedPerson = z.intersection(Person, Employee);
@@ -1766,8 +1766,8 @@ By default, validation issues from checks are considered *continuable*; that is,
17661766
<Tab value=" 10000 ;Zod">
17671767
```ts
17681768
const myString = z.string()
1769-
.refine((val) => val.length > 8)
1770-
.refine((val) => val === val.toLowerCase());
1769+
.refine((val) => val.length > 8, { error: "Too short!" })
1770+
.refine((val) => val === val.toLowerCase(), { error: "Must be lowercase" });
17711771

17721772

17731773
const result = myString.safeParse("OH NO");
@@ -1781,8 +1781,8 @@ result.error.issues;
17811781
<Tab value="Zod Mini">
17821782
```ts zod/v4-mini
17831783
const myString = z.string().check(
1784-
z.refine((val) => val.length > 8),
1785-
z.refine((val) => val === val.toLowerCase())
1784+
z.refine((val) => val.length > 8, { error: "Too short!" }),
1785+
z.refine((val) => val === val.toLowerCase(), { error: "Must be lowercase" })
17861786
);
17871787

17881788
const result = z.safeParse(myString, "OH NO");
@@ -1801,8 +1801,8 @@ To mark a particular refinement as *non-continuable*, use the `abort` parameter.
18011801
<Tab value="Zod">
18021802
```ts
18031803
const myString = z.string()
1804-
.refine((val) => val.length > 8, { abort: true })
1805-
.refine((val) => val === val.toLowerCase());
1804+
.refine((val) => val.length > 8, { error: "Too short!", abort: true })
1805+
.refine((val) => val === val.toLowerCase(), { error: "Must be lowercase", abort: true });
18061806

18071807

18081808
const result = myString.safeParse("OH NO");
@@ -1813,8 +1813,8 @@ result.error!.issues;
18131813
<Tab value="Zod Mini">
18141814
```ts zod/v4-mini
18151815
const myString = z.string().check(
1816-
z.refine((val) => val.length > 8, { abort: true }),
1817-
z.refine((val) => val === val.toLowerCase(), { abort: true })
1816+
z.refine((val) => val.length > 8, { error: "Too short!", abort: true }),
1817+
z.refine((val) => val === val.toLowerCase(), { error: "Must be lowercase", abort: true })
18181818
);
18191819

18201820
const result = z.safeParse(myString, "OH NO");
@@ -2441,7 +2441,7 @@ The `z.templateLiteral` API can handle any number of string literals (e.g. `"hel
24412441
z.templateLiteral([ "hi there" ]);
24422442
// `hi there`
24432443

2444-
z.templateLiteral([ "email: ", z.string()]);
2444+
z.templateLiteral([ "email: ", z.string() ]);
24452445
// `email: ${string}`
24462446

24472447
z.templateLiteral([ "high", z.literal(5) ]);
@@ -2524,7 +2524,7 @@ Function schemas have an `.implement()` method which accepts a function and retu
25242524

25252525
```ts
25262526
const computeTrimmedLength = MyFunction.implement((input) => {
2527-
// TypeScript knows x is a string!
2527+
// TypeScript knows input is a string!
25282528
return input.trim().length;
25292529
});
25302530

packages/docs/content/v4/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ strbool.parse("1") // => true
750750
strbool.parse("yes") // => true
751751
strbool.parse("on") // => true
752752
strbool.parse("y") // => true
753-
strbool.parse("enable") // => true
753+
strbool.parse("enabled") // => true
754754
755755
strbool.parse("false"); // => false
756756
strbool.parse("0"); // => false

0 commit comments

Comments
 (0)
0