Skip to content

Commit 345864f

Browse files
committed
Improve library docs
1 parent 5cb48f7 commit 345864f

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

packages/docs/content/library-authors.mdx

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -190,17 +190,6 @@ inferSchema(z.string());
190190
// => ZodString
191191
```
192192

193-
The result is now fully and properly typed, you can extract & use the inferred type of the schema:
194-
195-
```ts
196-
function parseData<T extends z.ZodTypeAny>(data: unknown, schema: T): z.output<T> {
197-
return schema.parse(data);
198-
}
199-
200-
parseData("sup", z.string());
201-
// => string
202-
```
203-
204193
To constrain the input schema to a specific subclass:
205194

206195
```ts
@@ -231,3 +220,13 @@ inferSchema(z.number());
231220
// // Type 'number' is not assignable to type 'string'
232221
```
233222

223+
To parse data with the schema, use the top-level `z.parse`/`z.safeParse`/`z.parseAsync`/`z.safeParseAsync` functions. The `z.core.$ZodType` subclass has no methods on it. The usual parsing methods are implemented by Zod and Zod Mini, but are not available in Zod Core.
224+
225+
```ts
226+
function parseData<T extends z.core.$ZodType>(data: unknown, schema: T): z.output<T> {
227+
return z.parse(schema, data);
228+
}
229+
230+
parseData("sup", z.string());
231+
// => string
232+
```

packages/zod/src/v4/locales/en.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ const error: errors.$ZodErrorMap = (issue) => {
7373
switch (issue.code) {
7474
case "invalid_type":
7575
return `Invalid input: expected ${issue.expected}, received ${parsedType(issue.input)}`;
76-
// return `Invalid input: expected ${issue.expected}, received ${util.getParsedType(issue.input)}`;
76+
7777
case "invalid_value":
7878
if (issue.values.length === 1) return `Invalid input: expected ${util.stringifyPrimitive(issue.values[0])}`;
7979
return `Invalid option: expected one of ${util.joinValues(issue.values, "|")}`;

play.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import { z } from "zod/v4";
22

3-
console.dir(z.string(), { depth: null });
3+
z;

0 commit comments

Comments
 (0)