MapleLeaf ๐Ÿ
MapleLeaf ๐Ÿโ€ข17mo ago

Feature request: v.nullish(someValidator)

Equivalent to this:
export const nullish = <T>(validator: Validator<T>) =>
v.optional(v.union(validator, v.null()))
export const nullish = <T>(validator: Validator<T>) =>
v.optional(v.union(validator, v.null()))
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
ballingt
ballingtโ€ข17mo ago
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.

Did you find this page helpful?