zod 4.6.4 → 4.6.5

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zod",
3
- "version": "4.6.4",
3
+ "version": "4.6.5",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Colin McDonnell <zod@colinhacks.com>",
@@ -2841,7 +2841,8 @@ type ZodInstanceOfParams = core.Params<
2841
2841
 
2842
2842
  // ZodInstanceOf
2843
2843
  export interface ZodInstanceOf<T = unknown> extends ZodCustom<T, T> {
2844
- properties<Shape extends core.$ZodShape>(
2844
+ // the shape is keyed off the instance type, so keys autocomplete and a schema that can't accept the property's type is an error. Methods are excluded: every object literal inherits Object.prototype.toString, which would otherwise collide with the constraint's own toString entry and reject every shape.
2845
+ properties<Shape extends { [k in keyof T as T[k] extends Function ? never : k]?: core.$ZodType<unknown, T[k]> }>(
2845
2846
  shape: Shape,
2846
2847
  params?: string | core.$ZodCheckPropertiesParams
2847
2848
  ): ZodInstanceOf<T & core.$InferObjectInput<Shape, {}>>;
@@ -51,6 +51,25 @@ test("z.instanceof().properties()", () => {
51
51
  expectTypeOf<z.infer<typeof W>>().toEqualTypeOf<URL & { search: string }>();
52
52
  });
53
53
 
54
+ test("z.instanceof().properties() constrains the shape to the instance type", () => {
55
+ const file = z.instanceof(File).properties({ name: z.string(), size: z.number().max(1024) });
56
+ expectTypeOf<z.infer<typeof file>>().toEqualTypeOf<File & { name: string; size: number }>();
57
+
58
+ // @ts-expect-error no such property on File
59
+ z.instanceof(File).properties({ nmae: z.string() });
60
+
61
+ // @ts-expect-error File["size"] is a number
62
+ z.instanceof(File).properties({ size: z.string() });
63
+
64
+ // methods are out of the shape, so an object literal's inherited toString can't collide with the constraint
65
+ // @ts-expect-error
66
+ z.instanceof(File).properties({ text: z.any() });
67
+
68
+ // a literal still narrows a wider property
69
+ const png = z.instanceof(File).properties({ type: z.literal("image/png") });
70
+ expectTypeOf<z.infer<typeof png>>().toEqualTypeOf<File & { type: "image/png" }>();
71
+ });
72
+
54
73
  test("z.properties spreads into .check()", () => {
55
74
  // the 4.5 array call sites: the check yields itself from Symbol.iterator
56
75
  const p = z.properties({ a: z.literal("x") });
@@ -1,5 +1,5 @@
1
1
  export const version = {
2
2
  major: 4,
3
3
  minor: 6,
4
- patch: 4 as number,
4
+ patch: 5 as number,
5
5
  } as const;
@@ -788,7 +788,9 @@ export declare const describe: typeof core.describe;
788
788
  export declare const meta: typeof core.meta;
789
789
  type ZodInstanceOfParams = core.Params<ZodCustom, core.$ZodIssueCustom, "type" | "check" | "checks" | "fn" | "abort" | "error" | "params" | "path">;
790
790
  export interface ZodInstanceOf<T = unknown> extends ZodCustom<T, T> {
791
- properties<Shape extends core.$ZodShape>(shape: Shape, params?: string | core.$ZodCheckPropertiesParams): ZodInstanceOf<T & core.$InferObjectInput<Shape, {}>>;
791
+ properties<Shape extends {
792
+ [k in keyof T as T[k] extends Function ? never : k]?: core.$ZodType<unknown, T[k]>;
793
+ }>(shape: Shape, params?: string | core.$ZodCheckPropertiesParams): ZodInstanceOf<T & core.$InferObjectInput<Shape, {}>>;
792
794
  }
793
795
  export declare const ZodInstanceOf: core.$constructor<ZodInstanceOf>;
794
796
  declare function _instanceof<T extends typeof util.Class>(cls: T, params?: ZodInstanceOfParams): ZodInstanceOf<InstanceType<T>>;
@@ -788,7 +788,9 @@ export declare const describe: typeof core.describe;
788
788
  export declare const meta: typeof core.meta;
789
789
  type ZodInstanceOfParams = core.Params<ZodCustom, core.$ZodIssueCustom, "type" | "check" | "checks" | "fn" | "abort" | "error" | "params" | "path">;
790
790
  export interface ZodInstanceOf<T = unknown> extends ZodCustom<T, T> {
791
- properties<Shape extends core.$ZodShape>(shape: Shape, params?: string | core.$ZodCheckPropertiesParams): ZodInstanceOf<T & core.$InferObjectInput<Shape, {}>>;
791
+ properties<Shape extends {
792
+ [k in keyof T as T[k] extends Function ? never : k]?: core.$ZodType<unknown, T[k]>;
793
+ }>(shape: Shape, params?: string | core.$ZodCheckPropertiesParams): ZodInstanceOf<T & core.$InferObjectInput<Shape, {}>>;
792
794
  }
793
795
  export declare const ZodInstanceOf: core.$constructor<ZodInstanceOf>;
794
796
  declare function _instanceof<T extends typeof util.Class>(cls: T, params?: ZodInstanceOfParams): ZodInstanceOf<InstanceType<T>>;
@@ -4,7 +4,7 @@ exports.version = void 0;
4
4
  exports.version = {
5
5
  major: 4,
6
6
  minor: 6,
7
- patch: 4,
7
+ patch: 5,
8
8
  };
9
9
 
10
10
  // seal-cjs-exports
@@ -1,5 +1,5 @@
1
1
  export const version = {
2
2
  major: 4,
3
3
  minor: 6,
4
- patch: 4,
4
+ patch: 5,
5
5
  };