-
d312e6dThanks @jviide! - feat: always normalize custom errorsCustom errors listed in issue lists (
ValitaError.issueandValitaResult.issue) are now always normalized to match the type{ code: "custom_error", path: (string | number)[], message?: string | undefined }. -
e66a42eThanks @jviide! - Allow passing a type to .chain()The
.chain()method of types now accepts other types as-is:v.string() // Accept strings as input, .map((s) => Number(s)) // then parse the strings to numbers, .chain(v.literal(1)); // and ensure that the parsed number is 1.
The parsing mode is propagated to the chained type:
const example = v.unknown().parse(v.object({ a: v.number() })); example.parse({ a: 1, b: 2 }, { mode: "strip" }); // { a: 1 }
-
b9d9c30Thanks @jviide! - Add support for.nullable(() => x)The
.nullable()method now supports default value functions_similarly to.optional().
59b89beThanks @arv for reporting this! - Revert changes since v0.3.12 as they were backwards incompatible
8aaad50Thanks @jviide! - Mark.optional(() => ...)as non-experimental and recommend it over the now-deprecated.default(x)
-
f78c082Thanks @jviide! - Add experimental support for.optional(() => x)The
.optional()method now supports default value functions for replacingundefinedand missing values from the input and wrapped validator. The functionality is similar to.default(x), except thatdefaultFnhas to be a function and is executed for each validation run. This allows patterns like the following:const Item = v.object({ id: v.string() }); const Items = v.array(Item).optional(() => []);
This avoids a common pitfall with using
.default([])for the same pattern. As the newly created empty arrays are not shared, mutating them is safe(r) as it doesn't affect other validation outputs.This feature is marked experimental for the time being.
-
43513b6Thanks @jviide! - Add support for variadic tuple typesTuple and array types now have a new method,
.concat()that can be used to create variadic tuple types. -
43513b6Thanks @jviide! - Makev.array()a shorthand forv.array(v.unknown())