Closed richardscarrott closed 2 years ago
I guess or
and and
could also infer their types:
typeof nullish['__validType'] // undefined | null
typeof string['__validType'] // string
typeof or(nullish, string)['__validType'] // undefined | null | string
Feels like a massive abuse of a property which wouldn't exist at runtime though?
I know a few other libs take runtime validation definitions and infer the TS interface.
Ok computer offers the full expressiveness of JS to define validation logic -- i.e. a validator is a function that could do just about anything -- which I think may make this a little more challenging; however functions are objects, so an
annotate
fn like this might work: