MapleLeaf 🍁
MapleLeaf 🍁17mo ago

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
ian
ian17mo ago
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.
Indy
Indy17mo ago
We've definitely been thinking about Record! It's on our list.
RJ
RJ17mo ago
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.
export default query({
args: { myData: v.any() },
handler: ({ myData }: { myData: unknown }) => ...
})
export default query({
args: { myData: v.any() },
handler: ({ myData }: { myData: unknown }) => ...
})
(this is what I do now)
Indy
Indy17mo ago
Added v.unknown() to our internal tracker to consider. Thanks for requesting!
ian
ian16mo ago
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 type
MapleLeaf 🍁
MapleLeaf 🍁OP16mo ago
i 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>

Did you find this page helpful?