Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 222a663

Browse filesBrowse files
committed
Change ZodObject default to $strip. Set inst.shape in zod mini
1 parent de3517e commit 222a663
Copy full SHA for 222a663

File tree

Expand file treeCollapse file tree

4 files changed

+31
-12
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+31
-12
lines changed
Open diff view settings
Collapse file

‎packages/zod/src/v4/classic/schemas.ts‎

Copy file name to clipboardExpand all lines: packages/zod/src/v4/classic/schemas.ts
+2-4Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,7 @@ export function keyof<T extends ZodObject>(schema: T): ZodLiteral<keyof T["_zod"
10251025
export interface ZodObject<
10261026
/** @ts-ignore Cast variance */
10271027
out Shape extends core.$ZodShape = core.$ZodLooseShape,
1028-
out Config extends core.$ZodObjectConfig = core.$ZodObjectConfig,
1028+
out Config extends core.$ZodObjectConfig = core.$strip,
10291029
> extends _ZodType<core.$ZodObjectInternals<Shape, Config>>,
10301030
core.$ZodObject<Shape, Config> {
10311031
shape: Shape;
@@ -1108,9 +1108,7 @@ export const ZodObject: core.$constructor<ZodObject> = /*@__PURE__*/ core.$const
11081108
core.$ZodObject.init(inst, def);
11091109
ZodType.init(inst, def);
11101110

1111-
util.defineLazy(inst, "shape", () => {
1112-
return Object.fromEntries(Object.entries(inst._zod.def.shape));
1113-
});
1111+
util.defineLazy(inst, "shape", () => def.shape);
11141112
inst.keyof = () => _enum(Object.keys(inst._zod.def.shape)) as any;
11151113
inst.catchall = (catchall) => inst.clone({ ...inst._zod.def, catchall: catchall as any as core.$ZodType }) as any;
11161114
inst.passthrough = () => inst.clone({ ...inst._zod.def, catchall: unknown() });
Collapse file

‎packages/zod/src/v4/classic/tests/object.test.ts‎

Copy file name to clipboardExpand all lines: packages/zod/src/v4/classic/tests/object.test.ts
+26-4Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -433,13 +433,35 @@ test("passthrough index signature", () => {
433433
// });
434434

435435
test("assignability", () => {
436-
z.object({ a: z.string() }) satisfies z.ZodObject;
437-
z.object({ a: z.string() }).catchall(z.number()) satisfies z.ZodObject;
436+
z.object({ a: z.string() }) satisfies z.ZodObject<{ a: z.ZodString }>;
437+
z.object({ a: z.string() }).catchall(z.number()) satisfies z.ZodObject<{ a: z.ZodString }>;
438438
z.object({ a: z.string() }).strict() satisfies z.ZodObject;
439439
z.object({}) satisfies z.ZodObject;
440-
z.object({ "a?": z.string() }) satisfies z.ZodObject;
441-
z.object({ "?a": z.string() }) satisfies z.ZodObject;
442440

441+
z.looseObject({ name: z.string() }) satisfies z.ZodObject<
442+
{
443+
name: z.ZodString;
444+
},
445+
z.core.$loose
446+
>;
447+
z.looseObject({ name: z.string() }) satisfies z.ZodObject<{
448+
name: z.ZodString;
449+
}>;
450+
z.strictObject({ name: z.string() }) satisfies z.ZodObject<
451+
{
452+
name: z.ZodString;
453+
},
454+
z.core.$loose
455+
>;
456+
z.strictObject({ name: z.string() }) satisfies z.ZodObject<
457+
{
458+
name: z.ZodString;
459+
},
460+
z.core.$strict
461+
>;
462+
z.object({ name: z.string() }) satisfies z.ZodObject<{
463+
name: z.ZodString;
464+
}>;
443465
z.object({
444466
a: z.string(),
445467
b: z.number(),
Collapse file

‎packages/zod/src/v4/mini/schemas.ts‎

Copy file name to clipboardExpand all lines: packages/zod/src/v4/mini/schemas.ts
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ export function keyof<T extends ZodMiniObject>(schema: T): ZodMiniLiteral<keyof
695695
export interface ZodMiniObject<
696696
/** @ts-ignore Cast variance */
697697
out Shape extends core.$ZodShape = core.$ZodShape,
698-
out Config extends core.$ZodObjectConfig = core.$ZodObjectConfig,
698+
out Config extends core.$ZodObjectConfig = core.$strip,
699699
> extends ZodMiniType<any, any, core.$ZodObjectInternals<Shape, Config>>,
700700
core.$ZodObject<Shape, Config> {
701701
shape: Shape;
@@ -705,6 +705,7 @@ export const ZodMiniObject: core.$constructor<ZodMiniObject> = /*@__PURE__*/ cor
705705
(inst, def) => {
706706
core.$ZodObject.init(inst, def);
707707
ZodMiniType.init(inst, def);
708+
util.defineLazy(inst, "shape", () => def.shape);
708709
}
709710
);
710711
export function object<T extends core.$ZodLooseShape = Record<never, SomeType>>(
Collapse file

‎play.ts‎

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

3-
z;
4-
5-
console.dir(z.literal(Number.POSITIVE_INFINITY).parse(Number.POSITIVE_INFINITY), { depth: null });
3+
z.string().regex(/asdf/);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.