Zod Versions Save

TypeScript-first schema validation with static type inference

v3.23.6

2 weeks ago

Commits:

  • bc0095aab9e7254deb18701adc63de128ca2c742 Test on latest node
  • 6e5699a30373cc22879f2bcb6902fc138518c980 Lint on latest node
  • 1f466d9d00f446d7bed1962990e7a1ce813ab0d4 describe how one can protect from cyclical objects starting an infini… (#3447)
  • 3fed6f21e0ea7adc91aa0cc44f75bcf4e526d98e Add zod playground link (#3454)
  • 04e1f379f6989d23dd45660fcabc78f76d7834f8 Fixed freezing async ZodReadonly results (#3457)
  • b87e59d0e4bbb4403bf27243afdcda9fcdeec258 Update sponsor tiers (#3453)
  • 143886151bba3930bdcc10d34a1cff4bf9103ba8 Add copper tier (#3460)
  • ce3711e1384952d255769b9495f9bfadfb327291 add VSCode dev container support and documenation
  • 93b480b12ec3466cbd3b4182f7ce292e5c61528c v3.23.6

v3.23.5

2 weeks ago

Commits:

  • 110b8211f991b3e060ab2da4fec7b63d600439ad Update README_ZH.md (#3433)
  • c1910bdfc98709b8f14231e2cefc5a3be401e3ee Made ZodEnum take readonly string array (#3444)
  • 541a862e978f96eb391849a6bf16be84231aa1b3 3.23.5

v3.23.4

3 weeks ago

Commits:

  • 157b18d742c86d85b26a8421af46ad6d6d6b6ea7 Add 3.23 announcement
  • aedf93f1435a29463d915c3be45b4dcbeefa8cc1 Revert change to default Input
  • 45107f7a7230fe48ee24dc37e621422c9dc64ec4 v3.23.4

v3.23.3

3 weeks ago

Commits:

  • 103d2436f85872ca0e0e6247652989cc93d46a39 3.23.3

v3.23.2

3 weeks ago

Commits:

  • c340558d14f5222a2ca177e0591463c06cc5edc3 Update protocol
  • ef588d036f3e98b832796e9a681dbaf097631ea0 Fix t3env
  • 9df70dd71195df951c43f180fbe5e64ea1f835df 3.23.2

v3.23.1

3 weeks ago

This changes the default generics back to any to prevent breakages with common packager like @hookform/resolvers:

- class ZodType<Output = unknown, Def extends ZodTypeDef = ZodTypeDef, Input = unknown> {}
+ class ZodType<Output = any, Def extends ZodTypeDef = ZodTypeDef, Input = any> {}

Commits:

  • 59f48723d36c423d9e10b3bd52325a7998314230 Change unknown -> any for ZodType defaults
  • 2ff5ceb428634de0ea4501495039c05a8e95b60a 3.23.1

v3.23.0

3 weeks ago

Zod 3.23 is now available. This is the final 3.x release before Zod 4.0. To try it out:

npm install zod

Features

z.string().date()

Zod can now validate ISO 8601 date strings. Thanks @igalklebanov! https://github.com/colinhacks/zod/pull/1766

const schema = z.string().date();
schema.parse("2022-01-01"); // OK

z.string().time()

Zod can now validate ISO 8601 time strings. Thanks @igalklebanov! https://github.com/colinhacks/zod/pull/1766

const schema = z.string().time();
schema.parse("12:00:00"); // OK

You can specify sub-second precision using the precision option:

const schema = z.string().time({ precision: 3 });
schema.parse("12:00:00.123"); // OK
schema.parse("12:00:00.123456"); // Error
schema.parse("12:00:00"); // Error

z.string().duration()

Zod can now validate ISO 8601 duration strings. Thanks @mastermatt! https://github.com/colinhacks/zod/pull/3265

const schema = z.string().duration();
schema.parse("P3Y6M4DT12H30M5S"); // OK

Improvements to z.string().datetime()

Thanks @bchrobot https://github.com/colinhacks/zod/pull/2522

You can now allow unqualified (timezone-less) datetimes using the local: true flag.

const schema = z.string().datetime({ local: true });
schema.parse("2022-01-01T12:00:00"); // OK

Plus, Zod now validates the day-of-month correctly to ensure no invalid dates (e.g. February 30th) pass validation. Thanks @szamanr! https://github.com/colinhacks/zod/pull/3391

z.string().base64()

Zod can now validate base64 strings. Thanks @StefanTerdell! https://github.com/colinhacks/zod/pull/3047

const schema = z.string().base64();
schema.parse("SGVsbG8gV29ybGQ="); // OK

Improved discriminated unions

The following can now be used as discriminator keys in z.discriminatedUnion():

  • ZodOptional
  • ZodNullable
  • ZodReadonly
  • ZodBranded
  • ZodCatch
const schema = z.discriminatedUnion("type", [
  z.object({ type: z.literal("A").optional(), value: z.number() }),
  z.object({ type: z.literal("B").nullable(), value: z.string() }),
  z.object({ type: z.literal("C").readonly(), value: z.boolean() }),
  z.object({ type: z.literal("D").brand<"D">(), value: z.boolean() }),
  z.object({ type: z.literal("E").catch("E"), value: z.unknown() }),
]);

Misc

Breaking changes

There are no breaking changes to the public API of Zod. However some changes can impact ecosystem tools that rely on Zod internals.

ZodFirstPartySchemaTypes

Three new types have been added to the ZodFirstPartySchemaTypes union. This may impact some codegen libraries. https://github.com/colinhacks/zod/pull/3247

+  | ZodPipeline<any, any>
+  | ZodReadonly<any>
+  | ZodSymbol;

Unrecognized keys in .pick() and .omit()

This version fixes a bug where unknown keys were accidentally accepted in .pick() and omit(). This has been fixed, which could cause compiler errors in some user code. https://github.com/colinhacks/zod/pull/3255

z.object({ 
  name: z.string() 
}).pick({
  notAKey: true // no longer allowed
})

Bugfixes and performance

Docs and ecosystem

New Contributors

Full Changelog: https://github.com/colinhacks/zod/compare/v3.22.4...v3.23.0

v3.23.0-beta.0

1 month ago

Zod 3.23 is now in beta! This is the final 3.x release before Zod 4.0. To try it out:

npm install zod@beta

Features

z.string().date()

Zod can now validate ISO 8601 date strings. Thanks @igalklebanov! https://github.com/colinhacks/zod/pull/1766

const schema = z.string().date();
schema.parse("2022-01-01"); // OK

z.string().time()

Zod can now validate ISO 8601 time strings. Thanks @igalklebanov! https://github.com/colinhacks/zod/pull/1766

const schema = z.string().time();
schema.parse("12:00:00"); // OK

You can specify sub-second precision using the precision option:

const schema = z.string().time({ precision: 3 });
schema.parse("12:00:00.123"); // OK
schema.parse("12:00:00.123456"); // Error
schema.parse("12:00:00"); // Error

z.string().duration()

Zod can now validate ISO 8601 duration strings. Thanks @mastermatt! https://github.com/colinhacks/zod/pull/3265

const schema = z.string().duration();
schema.parse("P3Y6M4DT12H30M5S"); // OK

Improvements to z.string().datetime()

Thanks @bchrobot https://github.com/colinhacks/zod/pull/2522

You can now allow unqualified (timezone-less) datetimes using the local: true flag.

const schema = z.string().datetime({ local: true });
schema.parse("2022-01-01T12:00:00"); // OK

Plus, Zod now validates the day-of-month correctly to ensure no invalid dates (e.g. February 30th) pass validation. Thanks @szamanr! https://github.com/colinhacks/zod/pull/3391

z.string().base64()

Zod can now validate base64 strings. Thanks @StefanTerdell! https://github.com/colinhacks/zod/pull/3047

const schema = z.string().base64();
schema.parse("SGVsbG8gV29ybGQ="); // OK

Improved discriminated unions

The following can now be used as discriminator keys in z.discriminatedUnion():

  • ZodOptional
  • ZodNullable
  • ZodReadonly
  • ZodBranded
  • ZodCatch
const schema = z.discriminatedUnion("type", [
  z.object({ type: z.literal("A").optional(), value: z.number() }),
  z.object({ type: z.literal("B").nullable(), value: z.string() }),
  z.object({ type: z.literal("C").readonly(), value: z.boolean() }),
  z.object({ type: z.literal("D").readonly(), value: z.boolean() }),
  z.object({ type: z.literal("E").catch("E"), value: z.unknown() }),
]);

Misc

Breaking changes

There are no breaking changes to the public API of Zod. However some changes can impact ecosystem tools that rely on Zod internals.

ZodFirstPartySchemaTypes

Three new types have been added to the ZodFirstPartySchemaTypes union. This may impact some codegen libraries. https://github.com/colinhacks/zod/pull/3247

+  | ZodPipeline<any, any>
+  | ZodReadonly<any>
+  | ZodSymbol;

Default generics in ZodType

The third argument of the ZodType base class now defaults to unknown. This makes it easier to define recursive schemas and write generic functions that accept Zod schemas.

- class ZodType<Output = any, Def extends ZodTypeDef = ZodTypeDef, Input = Output> {}
+ class ZodType<Output = unknown, Def extends ZodTypeDef = ZodTypeDef, Input = unknown> {}

Unrecognized keys in .pick() and .omit()

This version fixes a bug where unknown keys were accidentally accepted in .pick() and omit(). This has been fixed, which could cause compiler errors in some user code. https://github.com/colinhacks/zod/pull/3255

z.object({ 
  name: z.string() 
}).pick({
  notAKey: true // no longer allowed
})

Bugfixes and performance

Docs and ecosystem

New Contributors

Full Changelog: https://github.com/colinhacks/zod/compare/v3.22.4...v3.23.0-beta

v3.22.4

7 months ago

Commits:

  • d931ea3f0f15a6ae64f5f68e3c03912dffb2269d Lint
  • 8e634bd600093b7161487bed705279c892395118 Fix prettier
  • 4018d88f0e94992b2987428c4fda387b99ae2a53 docs: add @sanity-typed/zod to ecosystem (#2731)
  • 15ba5a4d4cb5be5af23771de0ba1346b4ba20a0e docs: add zod-sandbox to README ecosystem links (#2707)
  • 699ccae13b875d4fcadac268fd789c93b6ce8aef Export jsdoc with @deprecated when building (#2717)
  • dfe3719eae250ab3eca2d276da6c292867899cc6 Fix sanity-typed links (#2840)
  • cd7991e04a550868bfcb5b5d46e5eb5bc7edf5f3 fix ulid regex (#2225)
  • 7cb4ba2f85dd6b28290dda5de80ed54dfd2a793c Remove stalebot
  • 9340fd51e48576a75adc919bff65dbc4a5d4c99b Lazy emojiRegex
  • e7a9b9b3033991be6b4225f1be21da39c250bbb0 3.22.4

v3.22.3

7 months ago

Commits:

  • 1e23990bcdd33d1e81b31e40e77a031fcfd87ce1 Commit
  • 9bd3879b482f139fd03d5025813ee66a04195cdd docs: remove obsolete text about readonly types (#2676)
  • f59be093ec21430d9f32bbcb628d7e39116adf34 clarify datetime ISO 8601 (#2673)
  • 64dcc8e2b16febe48fa8e3c82c47c92643e6c9e3 Update sponsors
  • 18115a8f128680b4526df58ce96deab7dce93b93 Formatting
  • 28c19273658b164c53c149785fa7a8187c428ad4 Update sponsors
  • ad2ee9ccf723c4388158ff6b8669c2a6cdc85643 2718 Updated Custom Schemas documentation example to use type narrowing (#2778)
  • ae0f7a2c15e7741ee1b23c03a3bfb9acebd86551 docs: update ref to discriminated-unions docs (#2485)
  • 2ba00fe2377f4d53947a84b8cdb314a63bbd6dd4 [2609] fix ReDoS vulnerability in email regex (#2824)
  • 1e61d76cdec05de9271fc0df58798ddf9ce94923 3.22.3