zod 4.1.0-canary.20250804T184136 → 4.1.0-canary.20250806T000520
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/v4/classic/schemas.ts +2 -2
- package/src/v4/classic/tests/object.test.ts +15 -0
- package/src/v4/core/core.ts +2 -2
- package/src/v4/core/versions.ts +1 -1
- package/src/v4/mini/schemas.ts +2 -2
- package/src/v4/mini/tests/object.test.ts +6 -0
- package/v4/classic/schemas.cjs +1 -1
- package/v4/classic/schemas.d.cts +1 -1
- package/v4/classic/schemas.d.ts +1 -1
- package/v4/classic/schemas.js +1 -1
- package/v4/core/core.d.cts +2 -2
- package/v4/core/core.d.ts +2 -2
- package/v4/core/versions.cjs +1 -1
- package/v4/core/versions.js +1 -1
- package/v4/mini/schemas.cjs +1 -1
- package/v4/mini/schemas.d.cts +1 -1
- package/v4/mini/schemas.d.ts +1 -1
- package/v4/mini/schemas.js +1 -1
package/package.json
CHANGED
|
@@ -1038,9 +1038,9 @@ export function array<T extends core.SomeType>(element: T, params?: string | cor
|
|
|
1038
1038
|
}
|
|
1039
1039
|
|
|
1040
1040
|
// .keyof
|
|
1041
|
-
export function keyof<T extends ZodObject>(schema: T):
|
|
1041
|
+
export function keyof<T extends ZodObject>(schema: T): ZodEnum<util.KeysEnum<T["_zod"]["output"]>> {
|
|
1042
1042
|
const shape = schema._zod.def.shape;
|
|
1043
|
-
return
|
|
1043
|
+
return _enum(Object.keys(shape)) as any;
|
|
1044
1044
|
}
|
|
1045
1045
|
|
|
1046
1046
|
// ZodObject
|
|
@@ -261,6 +261,21 @@ test("inferred enum type", async () => {
|
|
|
261
261
|
expectTypeOf<Enum>().toEqualTypeOf<"a" | "b">();
|
|
262
262
|
});
|
|
263
263
|
|
|
264
|
+
test("z.keyof returns enum", () => {
|
|
265
|
+
const User = z.object({ name: z.string(), age: z.number() });
|
|
266
|
+
const keysSchema = z.keyof(User);
|
|
267
|
+
expect(keysSchema.enum).toEqual({
|
|
268
|
+
name: "name",
|
|
269
|
+
age: "age",
|
|
270
|
+
});
|
|
271
|
+
expect(keysSchema._zod.def.entries).toEqual({
|
|
272
|
+
name: "name",
|
|
273
|
+
age: "age",
|
|
274
|
+
});
|
|
275
|
+
type Keys = z.infer<typeof keysSchema>;
|
|
276
|
+
expectTypeOf<Keys>().toEqualTypeOf<"name" | "age">();
|
|
277
|
+
});
|
|
278
|
+
|
|
264
279
|
test("inferred partial object type with optional properties", async () => {
|
|
265
280
|
const Partial = z.object({ a: z.string(), b: z.string().optional() }).partial();
|
|
266
281
|
type Partial = z.infer<typeof Partial>;
|
package/src/v4/core/core.ts
CHANGED
|
@@ -84,8 +84,8 @@ export class $ZodAsyncError extends Error {
|
|
|
84
84
|
// export type output<T extends schemas.$ZodType> = T["_zod"]["output"];
|
|
85
85
|
// export type input<T extends schemas.$ZodType> = T["_zod"]["input"];
|
|
86
86
|
// export type output<T extends schemas.$ZodType> = T["_zod"]["output"];
|
|
87
|
-
export type input<T> = T extends { _zod: { input: any } } ?
|
|
88
|
-
export type output<T> = T extends { _zod: { output: any } } ?
|
|
87
|
+
export type input<T> = T extends { _zod: { input: any } } ? T["_zod"]["input"] : unknown;
|
|
88
|
+
export type output<T> = T extends { _zod: { output: any } } ? T["_zod"]["output"] : unknown;
|
|
89
89
|
|
|
90
90
|
// Mk2
|
|
91
91
|
// export type input<T> = T extends { _zod: { "~input": any } }
|
package/src/v4/core/versions.ts
CHANGED
package/src/v4/mini/schemas.ts
CHANGED
|
@@ -712,9 +712,9 @@ export function array<T extends SomeType>(element: SomeType, params?: any): ZodM
|
|
|
712
712
|
}
|
|
713
713
|
|
|
714
714
|
// .keyof
|
|
715
|
-
export function keyof<T extends ZodMiniObject>(schema: T):
|
|
715
|
+
export function keyof<T extends ZodMiniObject>(schema: T): ZodMiniEnum<util.KeysEnum<T["shape"]>> {
|
|
716
716
|
const shape = schema._zod.def.shape;
|
|
717
|
-
return
|
|
717
|
+
return _enum(Object.keys(shape)) as any;
|
|
718
718
|
}
|
|
719
719
|
|
|
720
720
|
// ZodMiniObject
|
|
@@ -89,6 +89,12 @@ test("z.keyof", () => {
|
|
|
89
89
|
type UserKeys = z.infer<typeof userKeysSchema>;
|
|
90
90
|
expectTypeOf<UserKeys>().toEqualTypeOf<"name" | "age" | "email">();
|
|
91
91
|
expect(userKeysSchema).toBeDefined();
|
|
92
|
+
expect(userKeysSchema._zod.def.type).toBe("enum");
|
|
93
|
+
expect(userKeysSchema._zod.def.entries).toEqual({
|
|
94
|
+
name: "name",
|
|
95
|
+
age: "age",
|
|
96
|
+
email: "email",
|
|
97
|
+
});
|
|
92
98
|
expect(z.safeParse(userKeysSchema, "name").success).toBe(true);
|
|
93
99
|
expect(z.safeParse(userKeysSchema, "age").success).toBe(true);
|
|
94
100
|
expect(z.safeParse(userKeysSchema, "email").success).toBe(true);
|
package/v4/classic/schemas.cjs
CHANGED
|
@@ -590,7 +590,7 @@ function array(element, params) {
|
|
|
590
590
|
// .keyof
|
|
591
591
|
function keyof(schema) {
|
|
592
592
|
const shape = schema._zod.def.shape;
|
|
593
|
-
return
|
|
593
|
+
return _enum(Object.keys(shape));
|
|
594
594
|
}
|
|
595
595
|
exports.ZodObject = core.$constructor("ZodObject", (inst, def) => {
|
|
596
596
|
core.$ZodObject.init(inst, def);
|
package/v4/classic/schemas.d.cts
CHANGED
|
@@ -395,7 +395,7 @@ export interface ZodArray<T extends core.SomeType = core.$ZodType> extends _ZodT
|
|
|
395
395
|
}
|
|
396
396
|
export declare const ZodArray: core.$constructor<ZodArray>;
|
|
397
397
|
export declare function array<T extends core.SomeType>(element: T, params?: string | core.$ZodArrayParams): ZodArray<T>;
|
|
398
|
-
export declare function keyof<T extends ZodObject>(schema: T):
|
|
398
|
+
export declare function keyof<T extends ZodObject>(schema: T): ZodEnum<util.KeysEnum<T["_zod"]["output"]>>;
|
|
399
399
|
export interface ZodObject<
|
|
400
400
|
/** @ts-ignore Cast variance */
|
|
401
401
|
out Shape extends core.$ZodShape = core.$ZodLooseShape, out Config extends core.$ZodObjectConfig = core.$strip> extends _ZodType<core.$ZodObjectInternals<Shape, Config>>, core.$ZodObject<Shape, Config> {
|
package/v4/classic/schemas.d.ts
CHANGED
|
@@ -395,7 +395,7 @@ export interface ZodArray<T extends core.SomeType = core.$ZodType> extends _ZodT
|
|
|
395
395
|
}
|
|
396
396
|
export declare const ZodArray: core.$constructor<ZodArray>;
|
|
397
397
|
export declare function array<T extends core.SomeType>(element: T, params?: string | core.$ZodArrayParams): ZodArray<T>;
|
|
398
|
-
export declare function keyof<T extends ZodObject>(schema: T):
|
|
398
|
+
export declare function keyof<T extends ZodObject>(schema: T): ZodEnum<util.KeysEnum<T["_zod"]["output"]>>;
|
|
399
399
|
export interface ZodObject<
|
|
400
400
|
/** @ts-ignore Cast variance */
|
|
401
401
|
out Shape extends core.$ZodShape = core.$ZodLooseShape, out Config extends core.$ZodObjectConfig = core.$strip> extends _ZodType<core.$ZodObjectInternals<Shape, Config>>, core.$ZodObject<Shape, Config> {
|
package/v4/classic/schemas.js
CHANGED
|
@@ -484,7 +484,7 @@ export function array(element, params) {
|
|
|
484
484
|
// .keyof
|
|
485
485
|
export function keyof(schema) {
|
|
486
486
|
const shape = schema._zod.def.shape;
|
|
487
|
-
return
|
|
487
|
+
return _enum(Object.keys(shape));
|
|
488
488
|
}
|
|
489
489
|
export const ZodObject = /*@__PURE__*/ core.$constructor("ZodObject", (inst, def) => {
|
|
490
490
|
core.$ZodObject.init(inst, def);
|
package/v4/core/core.d.cts
CHANGED
|
@@ -30,12 +30,12 @@ export type input<T> = T extends {
|
|
|
30
30
|
_zod: {
|
|
31
31
|
input: any;
|
|
32
32
|
};
|
|
33
|
-
} ?
|
|
33
|
+
} ? T["_zod"]["input"] : unknown;
|
|
34
34
|
export type output<T> = T extends {
|
|
35
35
|
_zod: {
|
|
36
36
|
output: any;
|
|
37
37
|
};
|
|
38
|
-
} ?
|
|
38
|
+
} ? T["_zod"]["output"] : unknown;
|
|
39
39
|
export type { output as infer };
|
|
40
40
|
export interface $ZodConfig {
|
|
41
41
|
/** Custom error map. Overrides `config().localeError`. */
|
package/v4/core/core.d.ts
CHANGED
|
@@ -30,12 +30,12 @@ export type input<T> = T extends {
|
|
|
30
30
|
_zod: {
|
|
31
31
|
input: any;
|
|
32
32
|
};
|
|
33
|
-
} ?
|
|
33
|
+
} ? T["_zod"]["input"] : unknown;
|
|
34
34
|
export type output<T> = T extends {
|
|
35
35
|
_zod: {
|
|
36
36
|
output: any;
|
|
37
37
|
};
|
|
38
|
-
} ?
|
|
38
|
+
} ? T["_zod"]["output"] : unknown;
|
|
39
39
|
export type { output as infer };
|
|
40
40
|
export interface $ZodConfig {
|
|
41
41
|
/** Custom error map. Overrides `config().localeError`. */
|
package/v4/core/versions.cjs
CHANGED
package/v4/core/versions.js
CHANGED
package/v4/mini/schemas.cjs
CHANGED
|
@@ -435,7 +435,7 @@ function array(element, params) {
|
|
|
435
435
|
// .keyof
|
|
436
436
|
function keyof(schema) {
|
|
437
437
|
const shape = schema._zod.def.shape;
|
|
438
|
-
return
|
|
438
|
+
return _enum(Object.keys(shape));
|
|
439
439
|
}
|
|
440
440
|
exports.ZodMiniObject = core.$constructor("ZodMiniObject", (inst, def) => {
|
|
441
441
|
core.$ZodObject.init(inst, def);
|
package/v4/mini/schemas.d.cts
CHANGED
|
@@ -179,7 +179,7 @@ export interface ZodMiniArray<T extends SomeType = core.$ZodType> extends _ZodMi
|
|
|
179
179
|
}
|
|
180
180
|
export declare const ZodMiniArray: core.$constructor<ZodMiniArray>;
|
|
181
181
|
export declare function array<T extends SomeType>(element: T, params?: string | core.$ZodArrayParams): ZodMiniArray<T>;
|
|
182
|
-
export declare function keyof<T extends ZodMiniObject>(schema: T):
|
|
182
|
+
export declare function keyof<T extends ZodMiniObject>(schema: T): ZodMiniEnum<util.KeysEnum<T["shape"]>>;
|
|
183
183
|
export interface ZodMiniObject<
|
|
184
184
|
/** @ts-ignore Cast variance */
|
|
185
185
|
out Shape extends core.$ZodShape = core.$ZodShape, out Config extends core.$ZodObjectConfig = core.$strip> extends ZodMiniType<any, any, core.$ZodObjectInternals<Shape, Config>>, core.$ZodObject<Shape, Config> {
|
package/v4/mini/schemas.d.ts
CHANGED
|
@@ -179,7 +179,7 @@ export interface ZodMiniArray<T extends SomeType = core.$ZodType> extends _ZodMi
|
|
|
179
179
|
}
|
|
180
180
|
export declare const ZodMiniArray: core.$constructor<ZodMiniArray>;
|
|
181
181
|
export declare function array<T extends SomeType>(element: T, params?: string | core.$ZodArrayParams): ZodMiniArray<T>;
|
|
182
|
-
export declare function keyof<T extends ZodMiniObject>(schema: T):
|
|
182
|
+
export declare function keyof<T extends ZodMiniObject>(schema: T): ZodMiniEnum<util.KeysEnum<T["shape"]>>;
|
|
183
183
|
export interface ZodMiniObject<
|
|
184
184
|
/** @ts-ignore Cast variance */
|
|
185
185
|
out Shape extends core.$ZodShape = core.$ZodShape, out Config extends core.$ZodObjectConfig = core.$strip> extends ZodMiniType<any, any, core.$ZodObjectInternals<Shape, Config>>, core.$ZodObject<Shape, Config> {
|
package/v4/mini/schemas.js
CHANGED
|
@@ -323,7 +323,7 @@ export function array(element, params) {
|
|
|
323
323
|
// .keyof
|
|
324
324
|
export function keyof(schema) {
|
|
325
325
|
const shape = schema._zod.def.shape;
|
|
326
|
-
return
|
|
326
|
+
return _enum(Object.keys(shape));
|
|
327
327
|
}
|
|
328
328
|
export const ZodMiniObject = /*@__PURE__*/ core.$constructor("ZodMiniObject", (inst, def) => {
|
|
329
329
|
core.$ZodObject.init(inst, def);
|