Skip to content

Conversation

@uicontent
Copy link
Collaborator

This PR contains the following updates:

Package Type Update Change
zod (source) devDependencies minor ^3.11.6 -> ^3.20.6

Release Notes

colinhacks/zod

v3.20.6

Compare Source

Commits:

v3.20.5

Compare Source

Commits:

  • e71c7be Fix extract/exclude type error

v3.20.4

Compare Source

Commits:

v3.20.3

Compare Source

Features

Fixes and documentation

New Contributors

Full Changelog: colinhacks/zod@v3.20.2...v3.20.3

v3.20.2

Compare Source

Commits:

v3.20.1

Compare Source

Commits:

v3.20.0: -beta

Compare Source

Breaking changes

There are no breaking API changes, however TypeScript versions 4.4 and earlier are no longer officially supported.

New features

The most feature-packed release since Zod 3.0!

.pipe()

A new schema method .pipe() is now available on all schemas. which can be used to chain multiple schemas into a "validation pipeline". Typically this will be used in conjunction with .transform().

z.string()
  .transform(val => val.length)
  .pipe(z.number().min(5))

The .pipe() method returns a ZodPipeline instance.

z.coerce

Zod now provides a more convenient way to coerce primitive values.

const schema = z.coerce.string();
schema.parse("tuna"); // => "tuna"
schema.parse(12); // => "12"
schema.parse(true); // => "true"

During the parsing step, the input is passed through the String() function, which is a JavaScript built-in for coercing data into strings. Note that the returned schema is a ZodString instance so you can use all string methods.

z.coerce.string().email().min(5);

All primitive types support coercion.

z.coerce.string();   // String(input)
z.coerce.number();   // Number(input)
z.coerce.boolean();  // Boolean(input)
z.coerce.bigint();   // BigInt(input)
z.coerce.date();     // new Date(input)
.catch()

A new schema method .catch() is now available on all schemas. It can be used to provide a "catchall" value that will be returned in the event of a parsing error.

const schema = z.string().catch("fallback");

schema.parse("kate"); // => "kate"
schema.parse(4); // => "fallback"

The .catch() method returns a ZodCatch instance.

z.symbol()

A long-missing hole in Zod's type system is finally filled! Thanks @​santosmarco-caribou.

const schema = z.symbol();
schema.parse(Symbol('asdf'));

Relatedly, you can also pass symbols into z.literal().

const TUNA = Symbol("tuna");
const schema = z.literal(TUNA);

schema.parse(TUNA); // Symbol(tuna)
schema.parse(Symbol("nottuna")); // Error
z.string().datetime()

A new method has been added to ZodString to validate ISO datetime strings. Thanks @​samchungy!

z.string().datetime();

This method defaults to only allowing UTC datetimes (the ones that end in "Z"). No timezone offsets are allowed; arbitrary sub-second precision is supported.

const dt = z.string().datetime();
dt.parse("2020-01-01T00:00:00Z"); // 🟢
dt.parse("2020-01-01T00:00:00.123Z"); // 🟢
dt.parse("2020-01-01T00:00:00.123456Z"); // 🟢 (arbitrary precision)
dt.parse("2020-01-01T00:00:00+02:00"); // 🔴 (no offsets allowed)

Offsets can be supported with the offset parameter.

const a = z.string().datetime({ offset: true });
a.parse("2020-01-01T00:00:00+02:00"); // 🟢 offset allowed

You can additionally constrain the allowable precision. This specifies the number of digits that should follow the decimal point.

const b = z.string().datetime({ precision: 3 })
b.parse("2020-01-01T00:00:00.123Z"); // 🟢 precision of 3 decimal points
b.parse("2020-01-01T00:00:00Z"); // 🔴 invalid precision
z.number().finite()

Restrict a number schema to finite values. Thanks @​igalklebanov.

const schema = z.number().finite();
schema.parse(5); 🟢
schema.parse(Infinity); 🔴
schema.parse(-Infinity); 🔴

What's Changed

New Contributors

Full Changelog: colinhacks/zod@v3.19.1...v3.20.0

v3.19.1

Compare Source

Commits:

v3.19.0

Compare Source

Features

Commits:

v3.18.0

Compare Source

Commits:

v3.17.10

Compare Source

Commits:

v3.17.9

Compare Source

Commits:

v3.17.8

Compare Source

Commits:

v3.17.7

Compare Source

Commits:

  • a59c384 Fix inferred function types

v3.17.6

Compare Source

Commits:

v3.17.5

Compare Source

Commits:

v3.17.4

Compare Source

What's Changed

New Contributors

Full Changelog: colinhacks/zod@v3.17.3...v3.17.4

v3.17.3

Compare Source

Commits:

v3.17.2

Compare Source

Commits:

  • 44916fe Remove circular dependency
  • 0b4bc1d Fix picking nonexistent keys

v3.17.0

Compare Source

Commits:

What's Changed

New Contributors

Full Changelog: colinhacks/zod@v3.16.1...v3.17.0

v3.16.1

Compare Source

Commits:

v3.16.0

Compare Source

Commits:

v3.15.1

Compare Source

Commits:

  • f814ef2 Improve docs
  • c190a84 Clean up type signature of ZodFormattedError

v3.15.0

Compare Source

Commits:

v3.14.5

Compare Source

Commits:

v3.14.4

Compare Source

Commits:

v3.14.3

Compare Source

Commits:

v3.14.2

Compare Source

Commits:


Configuration

📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 Ignore: Close this PR and you won't be reminded about this update again.


This PR has been generated by Renovate Bot.

@uicontent uicontent requested a review from a team as a code owner February 14, 2023 14:16
@uicontent uicontent added the dependencies Pull requests that update a dependency file label Feb 14, 2023
iobuhov
iobuhov previously approved these changes Feb 14, 2023
@iobuhov iobuhov merged commit 71ede3b into main Feb 16, 2023
@iobuhov iobuhov deleted the deps/zod-3.x branch February 16, 2023 08:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automation dependencies Pull requests that update a dependency file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants