Skip to content

Commit 80cfd3a

Browse files
committed
Improve runtime error for non-schema values in shape
1 parent d78c128 commit 80cfd3a

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77
- main
88
paths:
99
- "packages/zod/package.json"
10+
- "packages/zod/src/**"
1011
- ".github/workflows/release.yml"
1112

1213
jobs:

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,12 +1156,10 @@ export function object<T extends core.$ZodLooseShape = Partial<Record<never, cor
11561156
): ZodObject<util.Writeable<T> & {}, core.$strip> {
11571157
const def: core.$ZodObjectDef = {
11581158
type: "object",
1159-
11601159
get shape() {
11611160
util.assignProp(this, "shape", { ...shape });
11621161
return this.shape;
11631162
},
1164-
11651163
...util.normalizeParams(params),
11661164
};
11671165
return new ZodObject(def) as any;

packages/zod/src/v4/core/schemas.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,6 +1626,11 @@ export const $ZodObject: core.$constructor<$ZodObject> = /*@__PURE__*/ core.$con
16261626

16271627
const _normalized = util.cached(() => {
16281628
const keys = Object.keys(def.shape);
1629+
for (const k of keys) {
1630+
if (!(def.shape[k] instanceof $ZodType)) {
1631+
throw new Error(`Invalid element at key "${k}": expected a Zod schema`);
1632+
}
1633+
}
16291634
const okeys = util.optionalKeys(def.shape);
16301635

16311636
return {

play.ts

Lines 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-
console.dir(z.toJSONSchema(z.string().startsWith("hello").includes("cruel").endsWith("world").regex(/stuff/)), {
4-
depth: null,
5-
});
3+
console.dir(z.string(), { depth: null });

0 commit comments

Comments
 (0)