You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit de65a5c
Browse filesBrowse the repository at this point in the historyBrowse files
docs: lead the properties section with the check and add a Zod Mini tab (#6598)
z.properties() is a check again since #6594, so the section now opens with
the spread form both Zod and Zod Mini have, in a tab pair. The z.instanceof()
method follows as the Zod-only sugar that narrows the inferred type.
Also states that z.instanceof() returns the exact object passed in. The
no-clone fact moves up to the Instanceof intro, where it covers every
instance schema rather than just the properties check.
Copy file name to clipboardExpand all lines: packages/docs/content/api.mdx
+43-9Lines changed: 43 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2324,6 +2324,14 @@ z.instanceof(URL);
2324
2324
z.instanceof(Error);
2325
2325
```
2326
2326
2327
+
Parsing returns the exact object that was passed in. Unlike `z.object()`, nothing is cloned, so the prototype, the unlisted properties, and the object identity all survive.
2328
+
2329
+
```ts
2330
+
const url =newURL("https://example.com");
2331
+
2332
+
z.instanceof(URL).parse(url) ===url; // true
2333
+
```
2334
+
2327
2335
### `z.property()`[#property]
2328
2336
2329
2337
To validate a particular property of a class instance against a Zod schema:
okResponse.parse(newResponse("", { status: 404 })); // ❌ status
2388
+
```
2389
+
</Tab>
2390
+
</Tabs>
2391
+
2392
+
Each property is asserted in place. The schemas in the shape are validated but their results are discarded, so a transform or a default never changes the parsed value.
2393
+
2394
+
In Zod, `z.instanceof()` also has a `.properties()` method. It spreads the same check and narrows the inferred type:
The check asserts each property in place. Unlike `z.object()`, it never builds a new object, so prototypes, unlisted keys, and object identity survive. Schemas inside the shape are validated but their results are discarded, so a transform or a default never changes the parsed value.
2369
-
2370
-
The underlying `z.properties()` is a check, so it spreads into `.check()` too: `z.instanceof(Response).check(...z.properties({ ... }))`. It asserts on whatever the base schema produced, so `z.string().check(...z.properties({ length: z.number().min(3) }))` reads a string's length.
2371
-
2372
2406
## Refinements
2373
2407
2374
2408
Every Zod schema stores an array of *refinements*. Refinements are a way to perform custom validation that Zod doesn't provide a native API for.
0 commit comments