Closed QuentinLemCode closed 3 weeks ago
obj.keyof()
returns a schema, you can't use it as a value, do something like this:
function checkKey(key: string) {
const result = obj.keyof().safeParse(key)
if(result.success) {
needCorrectType(result.data, {})
}
}
obj.keyof()
returns a schema, you can't use it as a value, do something like this:function checkKey(key: string) { const result = obj.keyof().safeParse(key) if(result.success) { needCorrectType(result.data, {}) } }
Thank you very much 🙏
Hello,
I'm starting using Zod and I haven't figure out how to proper infer string union type from key of an object without using a type guard.
Here is a sample Zod schema :
And then I have a function that take a string in parameter and I would like to validate it's a key of the object and infer it.
Example stackblitz : https://stackblitz.com/edit/stackblitz-starters-qfu3yi?file=index.ts
Is this something possible without using type guard right now ? Maybe a potential feature ?