dannyelo
dannyelo5mo ago

v.string().isOptional property not working

Hello, I saw available the isOptional property in the v.string() But I have an error after I use it in the property name.
Type 'string' is not assignable to type 'Validator<any, OptionalProperty, any>'.ts(2322)
(property) color: "required"
Type 'string' is not assignable to type 'Validator<any, OptionalProperty, any>'.ts(2322)
(property) color: "required"
Any suggestion?
3 Replies
lee
lee5mo ago
can you describe what you're trying to do, or give the full code? It's possible you want v.optional(v.string())
dannyelo
dannyeloOP5mo ago
Yes, v.optional(v.string()) works ok. I just was curios I saw that property there. Thanks
lee
lee5mo ago
isOptional allows you to introspect a validator, so if you're given a validator you can determine whether it was constructed with v.optional. It's not useful for constructing new validators

Did you find this page helpful?