Feature request: v.record() and v.unknown()
I have a case where I want to store arbitrary data specifically as an object of type
Record<string, string | number>
but that doesn't seem to be possible with the current validators
As a somewhat related aside, v.unknown()
would be a much more welcome and safer alternative to v.any()
6 Replies
Record makes a lot of sense: I can also see the desire to have Record<Id<‘users’>, …>
I hadn’t thought about v.unknown before, that does sound safer.
We've definitely been thinking about
Record
! It's on our list.Seconded re:
v.unknown()
—when I need to use v.any()
in function validators, I always cast it to unknown
in the handler, but I'd love to not have to remember to do that. E.g.
(this is what I do now)Added v.unknown() to our internal tracker to consider. Thanks for requesting!
What do people think of something like
v.any<unknown>()
? Where you could specify what the type should be cast as.
That could alternatively support something like v.any<MyComplexType>()
as an escape hatch for when you want to have types but no validation.
I'm not sure if this is possible, just brainstorming from an ergonomics point of view, rather than making a custom v.unknown
that is similar to v.any
except the typei see the productivity argument, but it still feels really sketch to me
in fact we can kind of already do that by doing
v.any() as Validator<Something>