Feature request: v.nullish(someValidator)
Equivalent to this:
Because I often CBA whether an input is null or undefined :lul: so many data sources will just decide whether to do one or the other
1 Reply
I'd find this convenient too, here are some raw thoughts:
We've likely want
v.nullable(x)
which means v.union(v.null(), x)
. Then for nullish need to figure out how other languages are going to deal with a type that is optional and nullable; in Rust for example this could lead to significantly more complicated codegen for the argument struct where a field is both nullable and optional. Or maybe nullish is a special validator that accepts null or optional, but always spits out null โย then codegen in other languages doesn't need to be able to represent both. We don't have any validators that transform values like this yet, but it's a natural extension if the tradeoffs feel right.
For now this should be a userland extension, which makes it a little ugly (t.nullish()
or similar) but should work fine.