Releases: badrap/valita
Releases · badrap/valita
v0.1.1
v0.1.0
v0.0.26
v0.0.25
v0.0.24
-
Missing value errors from objects are now all collected:
const t = v.object({ a: v.string(), b: v.string() }); t.parse({}); // ValitaError: missing_value at .b (missing value) (+ 1 other issue)
-
When in strict mode (which is the default) all unrecognized keys in an object are collected into one error:
const t = v.object({}); t.parse({ x: 1, y: 2 }); // ValitaError: unrecognized_keys at . (unrecognized keys "x" and "y")
v0.0.23
v0.0.22
v0.0.21: Strictly Come Dancing
-
Breaking change: The default parsing mode is now
"strict"
. This means that extra keys for parsed objects cause the parsing to fail by default. For example this now fails:import * as v from "@badrap/valita"; const t = v.object({ a: v.number() }); t.parse({ "a": 1, "b": 2 }); // Uncaught ValitaError: unrecognized_key at . (unrecognized key "b")
You can go back to the default parsing mode (
"passthrough"
) by giving the mode to.parse(...)
(or.try(...)
). This will not fail, even with the extra key"b"
present:t.parse({ "a": 1, "b": 2 }, { mode: "passthrough" });
You can also opt-in to allowing extra keys case-by-case basis by using
.rest(...)
:const t = v.object({ a: v.number() }).rest(v.unknown()); t.parse({ "a": 1, "b": 2 }); // Succeeds, and the output type is { [x: string]: unknown; a: number; }
-
Docs galore: Huge thanks to @marvinhagemeister for documenting most of the API 🎉 (#20)