zod 4.1.0-canary.20250813T051310 → 4.1.0-canary.20250821T014902

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.1.0-canary.20250813T051310",
3
+ "version": "4.1.0-canary.20250821T014902",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Colin McDonnell <zod@colinhacks.com>",
@@ -118,6 +118,7 @@ export interface _ZodType<out Internals extends core.$ZodTypeInternals = core.$Z
118
118
  export const ZodType: core.$constructor<ZodType> = /*@__PURE__*/ core.$constructor("ZodType", (inst, def) => {
119
119
  core.$ZodType.init(inst, def);
120
120
  inst.def = def;
121
+ inst.type = def.type;
121
122
  Object.defineProperty(inst, "_def", { value: def });
122
123
 
123
124
  // base methods
@@ -827,3 +827,18 @@ test("def typing", () => {
827
827
  z.string().catch("fallback").def.type satisfies "catch";
828
828
  z.file().def.type satisfies "file";
829
829
  });
830
+
831
+ test("runtime type property exists and returns correct values", () => {
832
+ const stringSchema = z.string();
833
+ expect(stringSchema.type).toBe("string");
834
+ });
835
+
836
+ test("type narrowing works with type property", () => {
837
+ type ArrayOrRecord = z.ZodArray<z.ZodString> | z.ZodRecord<z.ZodString, z.ZodAny>;
838
+ const arraySchema = z.array(z.string()) as ArrayOrRecord;
839
+
840
+ if (arraySchema.type === "array") {
841
+ expectTypeOf(arraySchema).toEqualTypeOf<z.ZodArray<z.ZodString>>();
842
+ expect(arraySchema.element).toBeDefined();
843
+ }
844
+ });
@@ -168,9 +168,7 @@ export interface $ZodType<
168
168
  "~standard": $ZodStandardSchema<this>;
169
169
  }
170
170
  export interface _$ZodType<T extends $ZodTypeInternals = $ZodTypeInternals>
171
- extends $ZodType<T["output"], T["input"], T> {
172
- // _zod: T;
173
- }
171
+ extends $ZodType<T["output"], T["input"], T> {}
174
172
 
175
173
  export const $ZodType: core.$constructor<$ZodType> = /*@__PURE__*/ core.$constructor("$ZodType", (inst, def) => {
176
174
  inst ??= {} as any;
@@ -9,6 +9,7 @@ export interface ZodMiniType<
9
9
  out Input = unknown,
10
10
  out Internals extends core.$ZodTypeInternals<Output, Input> = core.$ZodTypeInternals<Output, Input>,
11
11
  > extends core.$ZodType<Output, Input, Internals> {
12
+ type: Internals["def"]["type"];
12
13
  check(...checks: (core.CheckFn<core.output<this>> | core.$ZodCheck<core.output<this>>)[]): this;
13
14
  clone(def?: Internals["def"], params?: { parent: boolean }): this;
14
15
  register<R extends core.$ZodRegistry>(
@@ -43,7 +44,9 @@ export const ZodMiniType: core.$constructor<ZodMiniType> = /*@__PURE__*/ core.$c
43
44
  if (!inst._zod) throw new Error("Uninitialized schema in ZodMiniType.");
44
45
 
45
46
  core.$ZodType.init(inst, def);
47
+
46
48
  inst.def = def;
49
+ inst.type = def.type;
47
50
  inst.parse = (data, params) => parse.parse(inst, data, params, { callee: inst.parse });
48
51
  inst.safeParse = (data, params) => parse.safeParse(inst, data, params);
49
52
  inst.parseAsync = async (data, params) => parse.parseAsync(inst, data, params, { callee: inst.parseAsync });
@@ -882,3 +882,18 @@ test("defaulted object schema returns shallow clone", () => {
882
882
  expect(result1).not.toBe(result2);
883
883
  expect(result1).toEqual(result2);
884
884
  });
885
+
886
+ test("runtime type property exists and returns correct values", () => {
887
+ const stringSchema = z.string();
888
+ expect(stringSchema.type).toBe("string");
889
+ });
890
+
891
+ test("type narrowing works with type property", () => {
892
+ type ArrayOrRecord = z.ZodMiniArray<z.ZodMiniString> | z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniAny>;
893
+ const arraySchema = z.array(z.string()) as ArrayOrRecord;
894
+
895
+ if (arraySchema.type === "array") {
896
+ expectTypeOf(arraySchema).toEqualTypeOf<z.ZodMiniArray<z.ZodMiniString<unknown>>>();
897
+ expect(arraySchema.def.element).toBeDefined();
898
+ }
899
+ });
@@ -115,6 +115,7 @@ const parse = __importStar(require("./parse.cjs"));
115
115
  exports.ZodType = core.$constructor("ZodType", (inst, def) => {
116
116
  core.$ZodType.init(inst, def);
117
117
  inst.def = def;
118
+ inst.type = def.type;
118
119
  Object.defineProperty(inst, "_def", { value: def });
119
120
  // base methods
120
121
  inst.check = (...checks) => {
@@ -6,6 +6,7 @@ import * as parse from "./parse.js";
6
6
  export const ZodType = /*@__PURE__*/ core.$constructor("ZodType", (inst, def) => {
7
7
  core.$ZodType.init(inst, def);
8
8
  inst.def = def;
9
+ inst.type = def.type;
9
10
  Object.defineProperty(inst, "_def", { value: def });
10
11
  // base methods
11
12
  inst.check = (...checks) => {
@@ -121,6 +121,7 @@ exports.ZodMiniType = core.$constructor("ZodMiniType", (inst, def) => {
121
121
  throw new Error("Uninitialized schema in ZodMiniType.");
122
122
  core.$ZodType.init(inst, def);
123
123
  inst.def = def;
124
+ inst.type = def.type;
124
125
  inst.parse = (data, params) => parse.parse(inst, data, params, { callee: inst.parse });
125
126
  inst.safeParse = (data, params) => parse.safeParse(inst, data, params);
126
127
  inst.parseAsync = async (data, params) => parse.parseAsync(inst, data, params, { callee: inst.parseAsync });
@@ -2,6 +2,7 @@ import * as core from "../core/index.cjs";
2
2
  import { util } from "../core/index.cjs";
3
3
  type SomeType = core.SomeType;
4
4
  export interface ZodMiniType<out Output = unknown, out Input = unknown, out Internals extends core.$ZodTypeInternals<Output, Input> = core.$ZodTypeInternals<Output, Input>> extends core.$ZodType<Output, Input, Internals> {
5
+ type: Internals["def"]["type"];
5
6
  check(...checks: (core.CheckFn<core.output<this>> | core.$ZodCheck<core.output<this>>)[]): this;
6
7
  clone(def?: Internals["def"], params?: {
7
8
  parent: boolean;
@@ -2,6 +2,7 @@ import * as core from "../core/index.js";
2
2
  import { util } from "../core/index.js";
3
3
  type SomeType = core.SomeType;
4
4
  export interface ZodMiniType<out Output = unknown, out Input = unknown, out Internals extends core.$ZodTypeInternals<Output, Input> = core.$ZodTypeInternals<Output, Input>> extends core.$ZodType<Output, Input, Internals> {
5
+ type: Internals["def"]["type"];
5
6
  check(...checks: (core.CheckFn<core.output<this>> | core.$ZodCheck<core.output<this>>)[]): this;
6
7
  clone(def?: Internals["def"], params?: {
7
8
  parent: boolean;
@@ -6,6 +6,7 @@ export const ZodMiniType = /*@__PURE__*/ core.$constructor("ZodMiniType", (inst,
6
6
  throw new Error("Uninitialized schema in ZodMiniType.");
7
7
  core.$ZodType.init(inst, def);
8
8
  inst.def = def;
9
+ inst.type = def.type;
9
10
  inst.parse = (data, params) => parse.parse(inst, data, params, { callee: inst.parse });
10
11
  inst.safeParse = (data, params) => parse.safeParse(inst, data, params);
11
12
  inst.parseAsync = async (data, params) => parse.parseAsync(inst, data, params, { callee: inst.parseAsync });